struct_list_sign_my_name.c

来源:互联网 发布:手机淘宝直通车怎么进 编辑:程序博客网 时间:2024/05/16 14:43

#include<stdio.h>
#define null 0;
struct person
{
char name[];
int id;
char adress[];
struct person * next;
struct person * last;

}
//one-direction struct list

struct person * create(int num)
{
int i;
struct person * p,q,head;
head=p=q=(struct person * )malloc(sizeof(struct person));
p->next=p->last=null;
if(num>1)
{
   for(i=2;i<=num;i++)//i represents number of crunodes
    {
    
     p=(struct person * )malloc(sizeof(struct person));
    
     p->last=q;
     q->next=p;
     //import the imformation of people
     q=p;
    }

}
p->next=null;
return head;
}

void finder(struct person * p)
{
if(p->name hasn not been visited)
{
   //sign my name
   p=p->next;
   finder(p);
}
else
{
   p=p->last;
   //find another person
   if (can not find)
   exit (0);
}
}

void main()

{
int num;
struct person * head;

   printf("Enter the number of person you want to visit:\n");
   scanf("%d",&num);
   head=create(num);
   finder(head);
   printf("It's the end!\n Work more tomorrow!\n");
  
  
  
}

0 0
原创粉丝点击