单链表的插入和删除

时间:2017-05-15 16:44:10
【文件属性】:
文件名称:单链表的插入和删除
文件大小:130KB
文件格式:DOC
更新时间:2017-05-15 16:44:10
数据结构 插入和删除 //==========用尾插入法建立带头结点的单链表=========== LinkList CreatListR1(void) { char ch[10]; LinkList head=(LinkList)malloc(sizeof(ListNode)); //生成头结点 ListNode *s,*r,*pp; r=head; r->next=NULL; printf("Input # to end "); //输入"#"代表输入结束 printf("Please input Node_data: "); scanf("%s",ch); //输入各结点的字符串 while(strcmp(ch,"#")!=0) { pp=LocateNode(head,ch); //按值查找结点,返回结点指针 if(pp==NULL) //没有重复的字符串,插入到链表中 { s=(ListNode *)malloc(sizeof(ListNode)); strcpy(s->data,ch); r->next=s; r=s; r->next=NULL; } printf("Input # to end "); printf("Please input Node_data: "); scanf("%s",ch); } return head; //返回头指针 }

网友评论