作者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
1F:推 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)
2F:→ bill8124:一楼辛苦了! 4点还在DEBUG 12/14 11:17