程序运行结果:
代码如下:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char id[500];
char password[500];
}Elemtype;
typedef struct
{
Elemtype data;
struct LNode *next;
}LNode,*LinkList;
void ListInsert(LinkList *L)
{
*L=(LNode*)malloc(sizeof(LNode));
(*L)->next=NULL;
}
void GetsList(LinkList *L,int i,Elemtype e)
{
LinkList p=*L;
int j=0;
while((p)&&(j<i-1))
{
p=p->next;
++j;
}
if((!p)||(j>i-1))
{
puts("error!");
return;
}
LinkList *s;
*s=(LNode*)malloc(sizeof(LNode));
(*s)->data=e;
(*s)->next=p->next;
p->next=*s;
}
void xinxi(Elemtype *e,char a[500],char b[500])
{
strcpy(e->id,a);
strcpy(e->password,b);
}
void f()
{
char d[]="第三链表程序";
char e[sizeof(d)+6];
sprintf(e,"title %s",d);
system(e);
puts(d);
LinkList L;
ListInsert(&L);
char *a[]={"三体","流浪地球","星舰地球"};
char *b[]={"120000000000000","12445999","1200000000023355"};
int c;
for(c=1;c<4;c++)
{
Elemtype e;
xinxi(&e,a[c-1],b[c-1]);
GetsList(&L,c,e);
}
PutsList(&L);
system("pause");
}
void PutsList(LinkList *L)
{
LinkList p=(*L)->next;
while(p)
{
printf("%s\t%s\n",p->data.id,p->data.password);
p=p->next;
}
}
main()
{
f();
return 0;
}