无表头单链表的总结----无限删除和无限插入(在主函数里实现)

 1 #include"head.h"
 2 int main()
 3 {
 4     struct Student *head;
 5     struct Student *addinfo;
 6     printf("请输入信息(101 wang f s 501)(以“0 0 0 s 0”作为结束标志):\n");
 7     head = input();
 8     print(head);
 9     char del_num[N];
10     printf("请输入要删除的号码(输入0终止删除):");
11     scanf_s("%s", del_num,N);
12     head = del(head,del_num);
13     print(head);
14     while (strcmp(del_num, "0") != 0)             //用while 循环“0”为终止条件
15     {
16         printf("请输入要删除的号码(输入0终止删除):");
17         scanf_s("%s", del_num, N);
18         head = del(head, del_num);
19         print(head);
20     }
21
22     printf("请输入要增加的信息(以“0 0 0 s 0”作为结束标志):\n");
23     addinfo = input();
24     while (addinfo != NULL)        ////用while 循环“0”为终止条件
25     {
26         head = insert(head, addinfo);
27         print(head);
28         printf("请输入要增加的信息(以“0 0 0 s 0”作为结束标志):\n");
29         addinfo = input();
30     }
31     return 0;
32 }
时间: 2024-11-03 03:25:04

无表头单链表的总结----无限删除和无限插入(在主函数里实现)的相关文章

无表头单链表的总结----删除节点

1 #include "head.h" 2 struct Student*del(struct Student*head,char num[N]) 3 { 4 struct Student*p1, *p2; 5 if (head == NULL) //若链表为空,则无需处理 6 { 7 printf("\nlist NULL!\n"); 8 return (head); 9 } 10 p2 = p1 = head; 11 while (strcmp(num, p1-

无表头单链表的总结----从链表中删除某一个年纪的的节点

1 #include "head.h" 2 struct Student *del_same_age(struct Student*head, int age) 3 { 4 struct Student *p, *pt; int find = 0; 5 p = pt = head; 6 while (p != NULL)//当循环到最后一个节点时 7 { 8 9 if (p->stu_age == age)//如果相等 10 { 11 find++; //说明找到了 12 if

无表头单链表的总结----两个链表合并

#include"head.h" struct Student* insert(struct Student*ahead, struct Student*bhead) { struct Student *pa1, *pa2, *pb1, *pb2; pa1 = pa2 = ahead; pb1 = pb2 = bhead; if ((ahead != NULL)&&(bhead != NULL)) { do { while ((pb1->num > pa1-

无表头单链表的总结----增加节点(原链表为有序的链表)

1 #include"head.h" 2 struct Student* insert(struct Student*head, struct Student*addinfo) 3 { 4 struct Student *p0, *p1, *p2; //开辟三个结构体指针 5 p2=p1 = head; //头指针赋给p1,p2 6 p0 = addinfo; //把 增加信息的指针赋给p0,习惯不用原来指针 7 if (head == NULL) 8 { 9 head = p0 //

无表头单链表的总结----如何将已经初始化的结构体数组加入链表关系

1 struct Student 2 { 3 char ID[N_ID]; 4 char name[N_name]; 5 struct Student *next; 6 }alist[LEN_A],blist[LEN_B]; 7 ////以上是结构体 8 //初始化 9 struct Student alist[LEN_A] = { {"101","Wang"} ,{"102","Li"},{"105",&

无表头单链表的总结----输出链表

#include"head.h" void print(struct Student* head) { struct Student *p; printf("There are %d records:\n", sum); p = head; if (p != NULL) { do { printf("%ld %d\n", p->num, p->score); p = p->next; } while (p != NULL); /

无表头单链表的总结----动态建立链表

1 #include "head.h" 2 struct Student *creat() 3 { 4 struct Student *head, *p1, *p2;// 先开辟三个结构体指针,*head,(作为返回的头指针) 5 p1 = p2 =(struct Student *) malloc(LEN); 6 scanf_s("%s %f", p1->num, N, &p1->score);//先读取输入的信息,据读入的信息进行判断 7 h

以指针和引用两种参数实现删除单链表L中所有值为X的结点的函数

下面是单链表的数据结构 typedef struct LNode{ ElemType data; struct LNode *next; }LNode,*Linklist; 1.以指针参数实现 void delete_x_1(LNode *head,ElemType x){//head为单链表头结点,删除结点的值为x LNode *l = head; LNode *p = head->next; while(p != null){ if(p->data == x){ l->next =

C语言实现单链表的遍历,逆序,插入,删除

单链表的遍历,逆序,插入,删除 #include<stdio.h> #include<stdlib.h> #include <string.h> #define bzero(a, b) memset(a, 0, b)//windows平台下无bzero函数. 增加宏拓展移植性 struct node { int data; //有效数据 struct node *pNext;//指向下一个节点的指针 }; struct node * make_node(int data