我都不好意思说自己学过链表了,帮我改下好吗?
程序代码:
#include <stdio.h> #include <string.h> #define LENGTH 20 typedef struct SqList { char name[LENGTH]; struct SqList *next; }SqList; /*链表的初始化和输出*/ SqList *InitSqList(SqList *h); void ShowList(SqList *h); int main() { SqList *head = NULL; head = InitSqList(head); ShowList(head); return 0; } /*链表的初始化*/ SqList *InitSqList(SqList *h) { SqList *p1, *p2; p1 = p2 = (SqList *)malloc(sizeof(SqList)); scanf("%s", p2->name); p2 = p2->next; while(!strcmp(p2->name, "#")) { if(h = NULL) { h = p2; } else { p1->next = p2; } p1 = p2; p2 = (SqList*)malloc(sizeof(SqList)); if(p2 != NULL) { scanf("%s", p2->name); p2 = p2->next; } } p2->next = NULL; return h; } /*链表的输出*/ void ShowList(SqList *h) { SqList *temp = h; while (temp->next != NULL) { printf("%s\t", temp->name); temp = temp->next; } }