作者bill8124 (沅)
看板b99902HW
標題Re: [課程] 單班計程作業 12
時間Sun Dec 12 23:36:04 2010
可以自己想測資的main
覺得不夠清楚的話就跟助教的函數搭配使用吧
還沒寫出來的同學們加油!! 祝大家早點10分~
--- 有鑑於重複呼叫各種函式的可能 改成可重複輸入的形式 ---
#include <conio.h>
int main(void)
{
int N1,N2,result;
int i,tmp,tmp2;
int friends[501];
char option,message[2][10]={"(failed)","(succeed)"};
Graph *g=(Graph *)malloc(sizeof(Graph));
assert(g);
init(g);
while(1)
{
printf("option?(1:add node, 2:add edge, 3:find friend, others:exit)");
option=getche();
switch(option)
{
case '1':
printf("\nInput a name:");
scanf("%d",&tmp);
result=add_node(g, tmp);
printf("add_node(g,%3d): %2d %s\n\n", tmp, result,
message[result+1]);
break;
case '2':
printf("\nInput two names:");
scanf("%d%d",&tmp,&tmp2);
result=add_edge(g, tmp, tmp2);
printf("add_edge(g,%3d,%3d): %2d %s\n\n", tmp, tmp2, result,
message[result+1]);
break;
case '3':
printf("\nWhose friends you wanna know?");
scanf("%d",&N1);
N2 = find_friends(g, N1, friends);
if (N2==-1)
printf("%d does not exist.\n\n",N1);
else
{
printf("%d has %d friends:\n",N1,N2);
for (i=0; i<N2; i++)
printf("%d\n", friends[i]);
}
break;
default:
printf("\n");
system("pause");
return 0;
break;
}
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.160.227.191
推 cluster159:推~~有這個程式抓BUG快多了~感謝 12/13 04:06
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:11)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:12)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:13)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:13)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:13)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 14:16)
※ 編輯: bill8124 來自: 140.112.91.122 (12/13 19:48)
→ bill8124:一樓辛苦了! 4點還在DEBUG 12/14 11:17