C语言 键盘输入 施工图

来源:百度知道 编辑:UC知道 时间:2024/06/20 10:12:42
对于给定的一个工程施工图,该图以边为单位从键盘输入,编写能够找出该图的关键路径的程序。

建立树:
struct node*create(struct node *head,int total)
{
struct node *p=NULL,*q=NULL;
int i;
p=(struct node*)malloc(sizeof(struct node));
p->child=NULL;
head=p;
for(i=0;i<total;i++)
{
q=(struct node*)malloc(sizeof(struct node));
q->data=i+1;
q->child=NULL;
p->next=q;
p=q;
}
p->next=NULL;
head->data=total;
return head;
}
struct node*creategraph(struct node *head)
{
struct node *p=head;
struct info *q=NULL,*r=NULL;
q=(struct info*)malloc(sizeof(struct info));
p=p->next;
p->child=q;
while(1) /*create the graph by the main list*/
{
while(1) /*by the child list*/
{
r=(struct info*)malloc(sizeof(struct info));
printf("Please input the node that which is the child of the node %d\n(0 is exit)",p->data);
scanf("%d",&r->node);
if(r->node==0)break;
printf("Ple