#include "ListManage.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void printList(LNode *head)
{
if(head==NULL)
exit(0);
printf(" ID name Sex teleNo addr email relation\n");
while(head->next!=NULL)
{
printf("%6d%10s%4d%12s%10s%20s%9d\n",head->data.memberID,head->data.name,head->data.sex,
head->data.teleNo,head->data.addr,head->data.email,head->data.relation);
head=head->next;
}
}
LNode *createLinkList()
{
LNode *stu1,*stu2,*stu3;
stu1 = (LNode *)malloc(sizeof(LNode));
stu2 = (LNode *)malloc(sizeof(LNode));
stu3 = (LNode *)malloc(sizeof(LNode));
stu1->data.memberID=1; strcpy(stu1->data.name,"zhang");
stu1->data.sex = FEMALE; strcpy(stu1->data.teleNo,"111111");
strcpy(stu1->data.addr,"aaaaaa"); strcpy(stu1->data.email,"zhang@scu.edu.cn");
stu1->data.relation=CLASSMATES;
stu2->data.memberID=2; strcpy(stu2->data.name,"wang");
stu2->data.sex = FEMALE; strcpy(stu2->data.teleNo,"2222222222");
strcpy(stu2->data.addr,"bbbbbb"); strcpy(stu2->data.email,"wang@scu.edu.cn");
stu2->data.relation=CLASSMATES;
stu3->data.memberID=3; strcpy(stu3->data.name,"Li");
stu3->data.sex = MALE; strcpy(stu3->data.teleNo,"33333333");
strcpy(stu3->data.addr,"bbbbbb"); strcpy(stu3->data.email,"Li@scu.edu.cn");
stu3->data.relation=CLASSMATES;
stu1->next=stu2;
stu2->next=stu3;
stu3->next=(LNode *)malloc(sizeof(LNode));
stu3->next->next=NULL;
return(stu1);
}
LNode *createLinkList(int count)
{
int i;
LNode *stu1,*stu2,*stu3;
stu1 = (LNode *)malloc(sizeof(LNode));
stu1->data.memberID=1; strcpy(stu1->data.name,"zhang");
stu1->data.sex = FEMALE; strcpy(stu1->data.teleNo,"111111");
strcpy(stu1->data.addr,"aaaaaa"); strcpy(stu1->data.email,"zhang@scu.edu.cn");
stu1->data.relation=CLASSMATES;
stu2=stu3=stu1;
for(i=0;i<count-1;i++){
stu2 = (LNode *)malloc(sizeof(LNode));
stu2->data.memberID=i+2; strcpy(stu2->data.name,"wang");
stu2->data.sex = FEMALE; strcpy(stu2->data.teleNo,"2222222222");
strcpy(stu2->data.addr,"bbbbbb"); strcpy(stu2->data.email,"wang@scu.edu.cn");
stu2->data.relation=CLASSMATES;
stu3->next=stu2;
stu3=stu2;
}
stu3->next=NULL;
return(stu1);
}
//测试以下函数的程序
//int GetLenthOfList(LinkList *L);
void Test_GetLenthOfList(LinkList *L)
{
int test_output;
printf("*****************************************************\n");
printf("text the function: int GetLenthOfList(LinkList *L);\n");
printf("the right output is: 3\n");
printf("*****************************************************\n");
//test_output=GetLenthOfList(L);
printf("the real output is:%d\n",test_output);
if(test_output!=3)
printf("----------error!!-----------\n");
}
void main()
{
LNode *head;
head = createLinkList(3);
//以下程序为数据初始化的输出结果,
printList(head);
}