单链表操作B
来源:互联网 发布:javascript void 0 编辑:程序博客网 时间:2024/06/07 02:06
数据结构上机测试2-2:单链表操作B
TimeLimit: 1000ms Memory limit: 65536K
题目描述
按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除(值相同的元素只保留最后输入的一个)。
输入
第一行输入元素个数n;
第二行输入n个整数。
输出
第一行输出初始链表元素个数;
第二行输出按照逆位序所建立的初始链表;
第三行输出删除重复元素后的单链表元素个数;
第四行输出删除重复元素后的单链表。
示例输入
10
2130 14 55 32 63 11 30 55 30
示例输出
10
3055 30 11 63 32 55 14 30 21
7
3055 11 63 32 14 21
#include <bits/stdc++.h>#define WW freopen("input.txt","r",stdin)#define RR freopen("ouput.txt","w",stdout)using namespace std;struct node{ int data; node *next;}*head;int n;void Creat(){ node *q; for(int i=1; i<=n; i++) { q=new node; q->next=head->next; cin>>q->data; head->next=q; }}void Ouput(){ node *p; p=head->next; cout<<n<<endl; while(p) { if(p!=head->next) cout<<" "; cout<<p->data; p=p->next; } cout<<endl;}void Delete(){ node *q,*p,*r; p=head->next; while(p) { q=p->next; r=p; while(q) { if(p->data==q->data) { r->next=q->next; free(q); q=r->next; n--; } else { q=q->next; r=r->next; } } p=p->next; }}int main(){ head=new node;head->next=NULL; cin>>n; Creat(); Ouput(); Delete(); Ouput(); return 0;}
0 0
- 单链表操作B
- SDUT 1139 单链表操作B
- 文件操作B
- B-树的操作
- 字符串操作 b
- B树基本操作
- B树相关操作
- B树操作详解
- Java操作ZooKeeper(B)
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 让vs2008与vs2012同时打开同一个项目文件
- apache+tomcat二级域名+url重写
- Velocity浅析及与Jsp、Freemarker对比
- Validate Binary Search Tree
- URL重写的几种实现方式的总结
- 单链表操作B
- spss效度检验方法
- 转载2014年四川高考零分作文:站不站起来,和拥不拥有全世界无关
- 设计模式之十三:适配器模式(Adapter)
- 顺序建立链表
- iOS中如何呼出另一个应用
- 【word001】如何解决Word中文字间距突然变大
- RMI介绍
- 转载2013最牛藏头诗高考作文,居然零分.太可惜了.《站在历史天空下的幻想》