尝试用链表代替数组来完成一个简易的系统设计,不过一开始没构思好,干脆用了单向链表加双向链表,稍显有点麻烦。
void show_main_menu(){
printf("1.添加用户\n");
printf("2.删除用户\n");
printf("3.查找用户\n");
printf("4.列出用户信息\n");
printf("0.退出\n");
printf("opt:");
}
首先打印主界面,实现如上功能,增删查找和排序。
typedef char S;
typedef struct SNode{
S data;
struct SNode* next;
}SNode;
typedef struct SNode * SLink;
typedef struct People{
int no;
SLink name;
SLink number;
SLink age;
SLink country;
}T;
typedef struct DNode{
T data;
struct DNode *prev;
struct DNode *next;
}DNode;
typedef struct DLinkNode{
struct DNode *head;
struct DNode *tail;
}DLinkNode;
typedef DLinkNode *DLink;
双向链表记录人员结构体,人员结构体内用单向链表记录数据。
此函数用来读入数据。
void slink_scanf(SLink link){
char c;
scanf("%c",&c);
while(c!='\n'){
slink_push_back(link,c);
scanf("%c",&c);
}
}