C语言单链表实现行李信息查询系统
#include <stdio.h> #include <stdlib.h> #include <string.h>
#define OK 1
typedef char Status;
typedef struct SqNode{ Status num[4], flight[7], name[5], ID[19], state[4]; struct SqNode *next; } LNode, *LinkList;
int InitList(LinkList &L) { L=(LinkList)malloc(sizeof(LNode)); L->next=NULL; return OK; }
int creatList(LinkList &Q) { Q->next = (LinkList)malloc(sizeof(LNode)); strcpy(Q->next->num, '001'); strcpy(Q->next->flight, 'UC8866'); strcpy(Q->next->name, '张里'); strcpy(Q->next->ID, '510199909090002'); strcpy(Q->next->state, '到达');
Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, '002');
strcpy(Q->next->flight, 'NI7755');
strcpy(Q->next->name, '李丽');
strcpy(Q->next->ID, '510200012290001');
strcpy(Q->next->state, '已取');
Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, '003');
strcpy(Q->next->flight, 'MQ9090');
strcpy(Q->next->name, '王一');
strcpy(Q->next->ID, '510198810090003');
strcpy(Q->next->state, '未取');
Q = Q->next;
Q->next = (LinkList)malloc(sizeof(LNode));
strcpy(Q->next->num, '004');
strcpy(Q->next->flight, 'BU8080');
strcpy(Q->next->name, '赵山');
strcpy(Q->next->ID, '610197708080022');
strcpy(Q->next->state, '未到达');
Q->next = NULL;
return OK;
}
char *seekList(LinkList L, char a[])
{
while(L->next != NULL)
{
if(strcmp(L->next->ID, a) == 0)
return L->next->state;
else
L = L->next;
}
return 'NULL';
}
int main() { char c[19]; LinkList L; InitList(L); creatList(L); printf('欢迎光临\n请输入身份证查找行李信息\n'); scanf('%s', c); char *d = seekList(L, c); if(strcmp(d, 'NULL') == 0) printf('查无此人\n'); else printf('%s', d); return 0; }
原文地址: https://www.cveoy.top/t/topic/oebj 著作权归作者所有。请勿转载和采集!