sdut oj1138 数据结构上机测试2-1:单链表操作A
来源:互联网 发布:地税局数据采集手续 编辑:程序博客网 时间:2024/06/14 13:46
题目链接:点击打开链接
数据结构上机测试2-1:单链表操作A
Time Limit: 1000ms Memory limit: 4096K 有疑问?点这里^_^
题目描述
输入n个整数,先按照数据输入的顺序建立一个带头结点的单链表,再输入一个数据m,将单链表中的值为m的结点全部删除。分别输出建立的初始单链表和完成删除后的单链表。
输入
第一行输入数据个数n;
第二行依次输入n个整数;
第三行输入欲删除数据m。
第二行依次输入n个整数;
第三行输入欲删除数据m。
输出
第一行输出原始单链表的长度;
第二行依次输出原始单链表的数据;
第三行输出完成删除后的单链表长度;
第四行依次输出完成删除后的单链表数据。
第二行依次输出原始单链表的数据;
第三行输出完成删除后的单链表长度;
第四行依次输出完成删除后的单链表数据。
示例输入
1056 25 12 33 66 54 7 12 33 1212
示例输出
1056 25 12 33 66 54 7 12 33 12756 25 33 66 54 7 33
代码实现:
#include <stdio.h>#include <stdlib.h>#include <string.h>using namespace std;struct node{ int data; node *next;};node *create(int n){ node *head,*tail,*p; head=new node; head->next=NULL; tail=head; for(int i=0;i<n;i++) { p=new node; scanf("%d",&p->data); tail->next=p; p->next=NULL; tail=p; } return head;}int Del(node *head,int n,int m){ node *p,*q; p=head; while(p->next) { q=p->next; if(q->data==m) { p->next=q->next; free(q); q=p->next; n--; } else { p=q; q=q->next; } } return n;}void print(node *head){ node *p; p=head->next; while(p) { if(p->next) printf("%d ",p->data); else printf("%d\n",p->data); p=p->next; }}int main(){ node *head; int n,m,t; scanf("%d",&n); head=create(n); scanf("%d",&m); printf("%d\n",n); print(head); t=Del(head,n,m); printf("%d\n",t); print(head); return 0;}
0 0
- sdut oj1138 数据结构上机测试2-1:单链表操作A
- SDUT 1138 数据结构上机测试2-1:单链表操作A
- [SDUT](1138)数据结构上机测试2-1:单链表操作A ---链表操作(线性表)
- 【1138】数据结构上机测试2-1:单链表操作A(顺序建表+删除节点)(SDUT)
- sdut oj1139 数据结构上机测试2-2单链表操作B
- 1138 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- SDUToj1138数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- Linux的发展史
- hdoj5301
- MVP设计模式初步学习
- Java主要特性
- UVA 10123(欧拉定理 + 大数类)
- sdut oj1138 数据结构上机测试2-1:单链表操作A
- UIsearchBar的placeholder字体颜色和大小
- IPhone 自定义 UITableViewCell 行缩进
- 转载 感谢原作者 矩阵分解在推荐系统中的应用:NMF和经典SVD实战
- NOI 2016
- tjut 4622
- Buffer is too small
- 了解PCB
- HDU 2187 悼念512汶川大地震遇难同胞——老人是真饿了