数据结构上机测试1:顺序表的应用
来源:互联网 发布:jquery 对象数组 编辑:程序博客网 时间:2024/06/05 08:09
题目描述
输入
第二行依次输入顺序表初始存放的n个元素值。
输出
第二行依次输出完成删除后的顺序表元素。
示例输入
125 2 5 3 3 4 2 5 7 5 4 3
示例输出
55 2 3 4 7
提示
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
int i,n;
struct node *p,*q,*head,*tail,*r;
scanf("%d",&n);
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
for(i=0;i<n;i++)
{
q=(struct node*)malloc(sizeof(struct node));
q->next=NULL;
scanf("%d",&q->data);
tail->next=q;
tail=q;
}
r=head->next;
while(r!=NULL)
{
p=r;
q=p->next;
while(q!=NULL)
{
if(r->data==q->data) //判断元素是否重复
{
n--; //元素个数减1
p->next=q->next; //删除元素
q=q->next;
}
else
{
p=q;
q=q->next;
}
}
r=r->next;
}
printf("%d\n",n);
r=head->next;
while(r!=NULL)
{
printf("%d",r->data);
if(r->next!=NULL)
printf(" ");
r=r->next;
}
printf("\n");
return 0;
}
- 数据结构上机测试1:顺序表的应用
- 1130数据结构上机测试1:顺序表的应用
- 1130 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用!!!
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- SDUToj1130数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 【1130】数据结构上机测试1:顺序表的应用
- PTA 5-31 字符串循环左移
- 使用nexus在linux部署私有仓库
- PAT B 1018. 锤子剪刀布
- 一个经典例子让你彻彻底底理解java回调机制
- 关于事件冒泡和默认行为的学习
- 数据结构上机测试1:顺序表的应用
- MAVEN报错:Missing artifact com.sun:tools:jar:1.5.0:system
- Linux 文件系统剖析
- 读取与解析XML数据
- Js判断参数(String,Array,Object)是否为undefined或者值为空
- Swift 学习2
- 第二章:快速入门
- CodeForces 599C Day at the Beach
- Android开发笔记之ViewPage实现导航页原理