创建一个链表、删除一个节点、插入一个节点--实验
来源:互联网 发布:dwg免费加密软件 编辑:程序博客网 时间:2024/03/29 09:50
创建一个链表、删除一个节点、插入一个节点:
(说明:在VC6.0能够正常运行,仅供参考)
#include <stdio.h>#include <malloc.h>int n=0;void print_list(struct student *head);struct student *creat();struct student *del(struct student *head,int num);struct student *insert(struct student *head,struct student *p);struct student{int num;float score;struct student *next;};int main(){int number;struct student *head,stu;head = NULL;head = creat();print_list(head);printf("please input the del number:\n");scanf("%d",&number);head = del(head,number);print_list(head);printf("please input the insert number:\n");scanf("%d,%f",&stu.num,&stu.score);head = insert(head,&stu);print_list(head);return 0;}/*************创建一个节点********************/struct student *creat(void){struct student *head,*tail,*p;head = tail = p = NULL;tail = p = (struct student *)malloc(sizeof(struct student));printf("please input the number:\n");scanf("%d,%f",&p->num,&p->score);while (p->num != 0){n = n+1;if (n == 1){head = p;}else{tail->next = p;tail = p;}p = malloc(sizeof(struct student));scanf("%d,%f",&p->num,&p->score);}tail->next = NULL;return (head);}/***************删除一个节点*****************/struct student *del(struct student *head,int num){struct student *p1,*p2;p1 = p2 = NULL;p1 = head;while (p1->num != num && p1->next != NULL){p2 = p1;p1 = p1->next;}if (num == p1->num){if (p1 == head){head = p1->next;}else{p2->next = p1->next;}printf("del the number:%d\n",num);}return (head);}/************插入一个节点**************/struct student *insert(struct student *head,struct student *p){struct student *p0,*p1,*p2;p1 = head;p0 = p;if (head == NULL){head = p0;p0->next = NULL;}else{while ((p0->num > p1->num)&&(p1->next != NULL)){p2 = p1;p1 = p1->next;}if (p0->num <= p1->num){if (head == p1) {head = p0;}else{p2->next = p0;p0->next = p1;}}}return (head);}void print_list(struct student *head){struct student *p;printf("now,these %d records are:\n",n);p = head;if (head != NULL){do {printf("%d,%f\n",p->num,p->score);p = p->next;} while (p != NULL);}}
- 创建一个链表、删除一个节点、插入一个节点--实验
- 实现双向链表删除一个节点P,在节点P后插入一个节点
- Oracle RAC删除一个节点_3节点的实验
- 删除一个链表中的节点
- 删除一个没有头节点链表中的某个节点
- 删除一个已知节点
- 无头单链表删除一个节点
- 创建一个ROS节点
- 用头插、尾插、按顺序插入创建一个不带头节点的链表
- 【算法之链表(三)】单链表中,在仅允许使用一个指针的情况下,在指定的节点前面插入以及删除一个节点
- 二叉排序树中删除一个节点
- xml实现删除一个节点
- 删除二叉排序树中的一个节点
- 用jquery删除一个节点
- 删除list中的一个节点
- 在无头单链表的一个节点前插入一个节点
- 链表中添加一个节点和删除一个节点
- 删除双向链表的一个指定节点
- mac下rar安装使用
- 10026 - Shoemaker's Problem
- DVD 自动分割软件
- java类私有成员在本类中可以任意访问
- ubuntu 下的jdk安装
- 创建一个链表、删除一个节点、插入一个节点--实验
- ORACLE 插入时间时显示'无效的月份'
- 模版下载地址
- Qt中采用多线程实现Socket编程-跨线程调用问题
- 发布一个开源项目 — Autohome增强插件(for chrome)
- sql脚本查询数据库表,数据,结构,约束等操作的方法
- 商务服务-建站设计思路搜索引擎SEO模型
- 高仿CMCC登录客户端
- frameset和frame的使用方法