sdut2122数据结构实验之链表七:单链表中重复元素的删除
2016-11-06 15:11
260 查看
#include<iostream> #include<stdlib.h> using namespace std; typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode,*LinkList; void show(LinkList L) { LinkList p; p=L->next; while(p) { if(p->next==NULL) cout<<p->data<<endl; else cout<<p->data<<" "; p=p->next; } } void CreateList_L(LinkList &L,int n) { LinkList p; p=new LNode; L=new LNode; L->next=NULL; LinkList q; q=new LNode; cin>>q->data; q->next=NULL; L->next=p; for(int i=2;i<=n;i++) { p=new LNode; cin>>p->data; p->next=q; L->next=p; q=p; } cout<<n<<endl; show(L); } void deletenum(LinkList &L,int n) { LinkList p,p1,p2; p=L; while(p->next!=NULL) { p1=p; p2=p->next; while(p2!=NULL) { if(p->data==p2->data) { p1->next=p2->next; p2=p2->next; n--; } else { p1=p1->next; p2=p2->next; } } p=p->next; } cout<<n<<endl; show(L); } int main() { LinkList L; int n; cin>>n; CreateList_L(L,n); deletenum(L,n); return 0; } /*************************************************** User name: TJRAC6015203228魏杰 Result: Accepted Take time: 0ms Take Memory: 156KB Submit time: 2016-11-01 13:59:38 ****************************************************/
相关文章推荐
- lintcode 容易题:Remove Duplicates from Sorted List 删除排序链表中的重复元素
- leetcode83,删除有序链表中的重复元素
- 数据结构之链表七:单链表中重复元素的删除
- 有序链表的重复元素删除
- 112. 删除排序链表中的重复元素
- 112删除排序链表中的重复元素
- leetcode-83. Remove Duplicates from Sorted List(删除有序链表中的重复元素)
- LintCode : 删除链表中的重复元素
- 删除链表中的重复元素
- 删除链表中的重复元素
- 数据结构实验之链表七:单链表中重复元素的删除
- 删除链表中的重复元素
- 数据结构实验之链表七:单链表中重复元素的删除
- 数据结构实验之链表七:单链表中重复元素的删除
- 数据结构实验之链表七:单链表中重复元素的删除
- 删除排序链表中的重复元素
- 容易 删除排序链表中的重复元素
- 删除排序链表中的重复元素
- 【1130】数据结构上机测试1:顺序表的应用 (链表的建立于重复元素删除) SDUT
- 给定一个排序链表,删除所有重复的元素每个元素只留下一个。