数据结构上机测试1:顺序表的应用
2014-01-16 08:06
344 查看
输入
第一行输入表的长度n;第二行依次输入顺序表初始存放的n个元素值。
输出
第一行输出完成多余元素删除以后顺序表的元素个数;第二行依次输出完成删除后的顺序表元素。
示例输入
12 5 2 5 3 3 4 2 5 7 5 4 3
示例输出
5 5 2 3 4 7
#include <stdio.h> #include <stdlib.h> using namespace std; struct node { int x; struct node *next; }*head,*a,*b; int main() { int n, i, s; scanf("%d",&n); head = new node; head->next = NULL; node *p = head; for(i = 0; i < n; i++) { node *q = new node; scanf("%d",&q->x); q->next=NULL; p->next=q; p=q; } for(node *p=head->next;p!=NULL;p=p->next) { s = p->x; a = p; b = a->next; while(b!=NULL) { if(b->x==s) { a->next = b->next; delete(b); b=a->next; n--; } else { a = a->next; b = a->next; } } } printf("%d\n",n); for(node *p=head->next;p!=NULL;p=p->next) { printf("%d ",p->x); } return 0; }
相关文章推荐
- 数据结构上机测试1:顺序表的应用!!!
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- SDUT1130数据结构上机测试1:顺序表的应用(上一个代码太蠢)
- 数据结构上机测试1:顺序表的应用
- SDUT 1130 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- SDUTACM数据结构上机测试1:顺序表的应用
- 1130数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- SDUToj1130数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用