您的位置:首页 > 理论基础 > 数据结构算法

【数据结构_顺序表_List_1038】顺序表中重复元素的删除

2017-03-09 20:41 357 查看
btw...我不知道怎么用顺序表做所以我是用链表做的,whatever,ac is OK 23333

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int num;
typedef struct node
{
int Length;
int data;
struct node *next;
}List;
int main()
{
List *L,*p,*q,*t;
L=(List *)malloc(sizeof(List));
int tar;
while(cin>>num)
{
p=L;
for(int i=0;i<num;i++)
{
q=(List *)malloc(sizeof(List));
cin>>q->data;
p->next=q;
p=q;
}
p->next=NULL;
/*t=L->next;
while(t!=NULL)
{
cout<<t->data<<" ";
t=t->next;
}
cout<<endl;*/
cin>>tar;
t=L->next;
int flag=0;
while(t!=NULL)
{
if(t->data==tar)
{
t=t->next;
continue;
}
else
{
cout<<t->data<<" ";
flag=1;
}
t=t->next;
}
if(flag==0) cout<<"-1";
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐