/*write by shenyu*/
/*create output free list*/
/*2006.1.8*/
#include <stdlib.h>
#define Max 10
struct List
{
int Number;
char Name[Max];
struct List *Next;
};
typedef struct List Node;
typedef Node *Link;
FreeList(Link Head)
{
Link Pointer;
while(Head != NULL)
{
Pointer = Head;
Head = Head->Next;
free(Pointer);
}
}
OutputList(Link Head)
{
Link Pointer;
Pointer = Head;
printf("Output the data/n");
while(Pointer != NULL)
{
printf("Data number:%d",Pointer->Number);
printf("Data name:%s/n",Pointer->Name);
Pointer = Pointer->Next;
}
}
CreateList(Link Head)
{
int DataNum;
char DataName[Max];
Link New;
Link Pointer;
int i;
Head =(Link)malloc(sizeof(Node));
if(Head == NULL)
printf("Memory allocate Failure!!/n");
else
{
DataNum = 1;
printf("please input the data name:");
scanf("%s",DataName);
Head->Number = DataNum;
for(i=0;i<=Max;i++)
{
Head->Name[i]=DataName[i];
}
Head->Next = NULL;
Pointer = Head;
while(1)
{
DataNum++;
New= (Link)malloc(sizeof(Node));
printf("please input the data name:");
scanf("%s",DataName);
if(DataName[0]=='0')
break;
New->Number = DataNum;
for(i=0;i<=Max;i++)
{
New->Name[i]=DataName[i];
}
New->Next = NULL;
Pointer->Next = New;
Pointer = New;
}
}
return Head;
}
main()
{
Link Head;
Head = CreateList(Head);
if(Head != NULL)
{
OutputList(Head);
FreeList(Head);
}
getch();
}