求指教 !!!用单链表建立一个学生通讯录咋把学生姓名和电话存进链表里啊 ???
求指教 !!!用单链表建立一个学生通讯录咋把学生姓名和电话存进链表里啊 ???
根据表的信息 建立结构体
构建链表
这些会了自然就知道 咋把学生姓名和电话存进链表里啊
//c.c #include <stdio.h> #include <stdlib.h> #include <assert.h> typedef int EMPTY;// typedef struct str_book {//建立结构体 EMPTY bccn_no; struct str_book * next; }str_book, *pstr_book; //创建 pstr_book create_book(void) { pstr_book ptmp = NULL; ptmp = malloc (sizeof(str_book)); assert(ptmp); ptmp->next = NULL; return ptmp; } //添加 int add_book(pstr_book pbook_list, pstr_book pbook_node) { assert(pbook_list && pbook_node); pbook_node->next = pbook_list->next; pbook_list->next = pbook_node; return 0;//成功 } //删除 int delete_book(const pstr_book pbook_list, const EMPTY empty) { pstr_book ptmp, ptmp_prev = pbook_list; assert(pbook_list); ptmp = ptmp_prev->next; while (ptmp) { if (empty == ptmp->bccn_no) {//删除 ptmp_prev->next = ptmp->next; free (ptmp); return 0;//成功 } ptmp_prev = ptmp_prev->next; ptmp = ptmp->next; } return -1;//失败 } //输出 void display_book(const pstr_book pbook_list) { pstr_book ptmp; assert(pbook_list); ptmp = pbook_list->next; while (ptmp) { printf ("%d\t", ptmp->bccn_no); ptmp = ptmp->next; } } int main(void) { pstr_book pbook_list = NULL; EMPTY empty; pbook_list = create_book(); while (scanf("%d", &empty) != EOF) { pstr_book ptmp = malloc (sizeof(str_book)); assert(ptmp); ptmp->next = NULL; ptmp->bccn_no = empty; add_book(pbook_list, ptmp); } delete_book(pbook_list, 5); display_book(pbook_list); printf ("\n"); return 0; }