数据结构上机测试2-1:单链表操作A
来源:互联网 发布:猪湾事件知乎 编辑:程序博客网 时间:2024/06/16 02:18
#include <iostream>#include <algorithm>#include <string>using namespace std;typedef struct node{ int data; node *next;}Linklist;Linklist *head, *p, *tail, *q;void nxcreat(int n)///逆序键链表{ head=new Linklist; head->next=NULL; while(n--) { p=new Linklist; cin>>p->data; p->next=head->next; head->next=p; }}void sxcreat(int n) ///顺序建链表{ head=new Linklist; head->next=NULL; tail=head; while(n--) { p=new Linklist; cin>>p->data; p->next=NULL; tail->next=p; tail=p; }}void display(){ p=head->next; while(p->next) { cout<<p->data<<" "; p=p->next; } cout<<p->data<<endl;}int del1(int n)///单链表重读元素删除{ Linklist *t; p=head->next; while(p) { t=p; q=p->next; while(q) { if(p->data==q->data) { n--; t->next=q->next; free(q); q=t->next; } else { q=q->next; t=t->next; } } p=p->next; } return n;}int del2(int n, int key)///删除值为key的节点{ p=head; while(p->next) { if(p->next->data==key) { n--; q=p->next; p->next=q->next; free(q); } else p=p->next; } return n;}int main(){ int n, m; cin>>n; sxcreat(n); cin>>m; cout<<n<<endl; display(); cout<<del2(n, m)<<endl; display(); return 0;}
1 0
- 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
- 数据结构上机测试2-1:单链表操作A
- 【1138】数据结构上机测试2-1:单链表操作A
- SDUT1138数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- Spring 国际化支持 消息传递 以及 AOP 面向方面编程
- poj 2965 The Pilots Brothers' refrigerator
- 随堂笔记7.27:方法的组成,递归方法------2
- 走进Git的世界
- POJ 2184 Cow Exhibition 01背包
- 数据结构上机测试2-1:单链表操作A
- The file “XXX” couldn’t be opened because you don’t have permission to view it.
- 南阳OJ 205 求余数
- HDU 2111 Saving HDU
- 递归阶乘
- 棋盘寻宝
- Spring中的事务
- css引入外部字体
- Linux下安装Apache