数据结构实验之链表七:单链表中重复元素的删除

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

按照数据输入的相反顺序(逆位序)建立一个单链表,并将单链表中重复的元素删除(值相同的元素只保留最后输入的一个)。

Input

第一行输入元素个数 n (1 <= n <= 15);

第二行输入 n 个整数,保证在 int 范围内。

Output

第一行输出初始链表元素个数;

第二行输出按照逆位序所建立的初始链表;

第三行输出删除重复元素后的单链表元素个数;

第四行输出删除重复元素后的单链表。

Sample Input

10

21 30 14 55 32 63 11 30 55 30

Sample Output

10

30 55 30 11 63 32 55 14 30 21

7

30 55 11 63 32 14 21

Hint

Source

不得使用数组!

链表的删除操作。

#include <stdio.h>
#include <string.h>
#include <stdlib.h> typedef struct node
{
int data;
struct node *next;
}link; link *newlink()
{
link *t;
t = (link*)malloc(sizeof(link));
t->next = NULL;
return t;
} link *create(int n)
{
link *head,*q;
int i;
head = newlink();
for(i=0;i<n;i++)
{
q = newlink();
scanf("%d",&q->data);
q->next = head->next;
head->next = q;
}
return head;
} void show(link *head)
{
link *p;
p = head->next;
while(p)
{
if(p->next==NULL)
printf("%d\n",p->data);
else
printf("%d ",p->data);
p = p->next;
}
} void del(int n,link *head)
{
link *p,*q,*r;
p = head;
while(p)
{
r = p;
q = p->next;
while(q)
{
if(q->data==p->data)
{
n--;
r->next = q->next;
free(q);
q = r->next;
}
else
{
r = q;
q = q->next;
}
}
p = p->next;
}
printf("%d\n",n);
show(head);
} int main()
{
int n;
link *head;
scanf("%d",&n);
head = create(n);
printf("%d\n",n);
show(head);
del(n,head);
return 0;
}

SDUT-2122_数据结构实验之链表七:单链表中重复元素的删除的更多相关文章

  1. SDUT OJ 数据结构实验之链表七:单链表中重复元素的删除

    数据结构实验之链表七:单链表中重复元素的删除 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...

  2. SDUT 3404 数据结构实验之排序七:选课名单.!?

    数据结构实验之排序七:选课名单 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 随着学校规模 ...

  3. SDUT 3346 数据结构实验之二叉树七:叶子问题

    数据结构实验之二叉树七:叶子问题 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...

  4. SDUT OJ 数据结构实验之二叉树七:叶子问题

    数据结构实验之二叉树七:叶子问题 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  5. SDUT 3379 数据结构实验之查找七:线性之哈希表

    数据结构实验之查找七:线性之哈希表 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 根据给定 ...

  6. SDUT 3363 数据结构实验之图论七:驴友计划

    数据结构实验之图论七:驴友计划 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 做为一个资深 ...

  7. SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度

    数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...

  8. 数据结构实验之链表七:单链表中重复元素的删除(SDUT 2122)

    #include <bits/stdc++.h> using namespace std; typedef struct node { int data; struct node* nex ...

  9. SDUT-3404_数据结构实验之排序七:选课名单

    数据结构实验之排序七:选课名单 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 随着学校规模的扩大,学生人数急剧增加,选 ...

随机推荐

  1. Tomcat中startup.bat启动无效

    error: Linux下启动和关闭tomcat报错,如下图所示: 而在windows下用cmd启动startup.bat也会报如上的错误: Neither the JAVA_HOME nor the ...

  2. java使用正则表达式,去除windows系统中文件名的非法路径

    w哦我爬取一个页面,并且把附件下载下来,保存,有的时候文件名,带*号,所以,无法保存 这时候就要删除所有的非法字符 String fileName = resourceName + fileTypt; ...

  3. Vue. 之 npm安装 axios

    Vue. 之 npm安装 axios 使用指令: cnpm install axios 

  4. 关系数据库理论 ch.6

    6.1 问题的提出 关系模式是一个5元组 R U,D,DOM,F U 属性 D 域 DOM 属性到域的映射 F 依赖 在本章中将关系模式看作 三元组 R U,D 属性-依赖 1NF 每一个分量是不可分 ...

  5. vue和element全局loading

    http请求的代码如下: import axios from 'axios' import { Message} from 'element-ui' import store from '../sto ...

  6. 【洛谷P1207】双重回文数 【USACO1.2】

    P1207 [USACO1.2]双重回文数 Dual Palindromes 题目描述 如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做"回文数".例如,12321就是一 ...

  7. Faster RCNN算法demo代码解析

    一. Faster-RCNN代码解释 先看看代码结构: Data: This directory holds (after you download them): Caffe models pre-t ...

  8. webpack学习之—— 模块热替换(Hot Module Replacement)

    模块热替换(HMR - Hot Module Replacement)功能会在应用程序运行过程中替换.添加或删除模块,而无需重新加载整个页面.主要是通过以下几种方式,来显著加快开发速度: 保留在完全重 ...

  9. Python中的进程池与线程池(包含代码)

    Python中的进程池与线程池 引入进程池与线程池 使用ProcessPoolExecutor进程池,使用ThreadPoolExecutor 使用shutdown 使用submit同步调用 使用su ...

  10. 笔记:投机和投资 F4NNIU

    笔记:投机和投资 F4NNIU 投机是零和交易. 投资是正和博弈. 投机看是短期,只关心当下. 投资是看的长期,更关注未来. 投机容易分散注意力. 投资更关心交易外的注意力. 投机像是看运气,运气有好 ...