#include<iostream>
#include<map>
using namespace std; class node{
public:
node():value(),next(NULL){}
~node(){}
int value;
node* next;
};///be careful this ; node* createlist(int a[],int n)
{
node* startnode = new node[n];
node* ret = startnode;
for(int i = ;i<n;i++)
{
startnode[i].value = a[i];
if(i<n-)
startnode[i].next = startnode + i + ;
}
cout<<endl;
return ret;
} void arraydeletedoublebymap()
{
int a[] = {,,,,,,,,,,,,,,};
// node * t = createlist(a,sizeof(a)/sizeof(a[0]));
map<int,int> m;
for(int i = ;i<sizeof(a)/sizeof(a[]);i++)
{
m.insert(pair<int,int>(a[i],));
} for(map<int,int>::iterator it = m.begin();it != m.end();it++)
{cout<<it->first;} ///其实输出的结果也是排序过的
} node* deletenode(node * t)
{
node* ret = t->next;
//delete t;
return ret;
} void helper(node * head)
{
map<int,int> m;
node* ret = head;
m.insert(pair<int,int>(head->value,));
node* pre = head;
head = head->next;
while(head)
{
cout<<head->value<<endl;
pair<map<int,int>::iterator,bool> ret = m.insert(pair<int,int>(head->value,));
if(ret.second == false)
{
pre->next = deletenode(head);
head = pre->next;
}else{
pre = head;
head = head->next;
}
} while(ret)
{
cout<<ret->value<<" ";
ret = ret->next;
}
} int main()
{
int a[] = {,,,,,,,,,,,,,,};
node * t = createlist(a,sizeof(a)/sizeof(a[]));
helper(t);
}

使用map做数组与链表去重的更多相关文章

  1. Set、Map及数组去重

    https://cloud.tencent.com/developer/article/1437254 https://blog.csdn.net/weixin_34247299/article/de ...

  2. 【数组模拟的链表or复杂模拟】PAT-L2-002. 链表去重

    L2-002. 链表去重 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的结点.即对任意键值K,只有键值或其绝对值等于K的第一个结点可以被保留.同时,所有被删除的结点必须 ...

  3. L2-002. 链表去重(数组模拟)

    L2-002. 链表去重 因为数值比较小,所以直接用数组来模拟 #include<cstdio> #include<cstring> #include<iostream& ...

  4. L2-002. 链表去重(map结构体,精彩的代码)

    链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值 ...

  5. 数组和链表--Java学习笔记(一)

    版权声明: 本文由Faye_Zuo发布于http://www.cnblogs.com/zuofeiyi/, 本文可以被全部的转载或者部分使用,但请注明出处. 我是一个全职妈妈,两年前在上海一家人力资源 ...

  6. L2-2. 链表去重

    L2-2. 链表去重 时间限制300 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越给定一个带整数键值的单链表L,本题要求你编写程序,删除那些键值的绝对值有重复的 ...

  7. C - Boxes in a Line 数组模拟链表

    You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to simul ...

  8. JAVA 基本数据结构--数组、链表、ArrayList、Linkedlist、hashmap、hashtab等

    概要 线性表是一种线性结构,它是具有相同类型的n(n≥0)个数据元素组成的有限序列.本章先介绍线性表的几个基本组成部分:数组.单向链表.双向链表:随后给出双向链表的C.C++和Java三种语言的实现. ...

  9. 团体程序设计天梯赛L2-002 链表去重 2017-03-22 18:12 25人阅读 评论(0) 收藏

    L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...

随机推荐

  1. RabbitMQ 笔记-RPC

    RabbitMQ中实现RPC的机制是: 客户端发送请求(消息)时,在消息的属性(MessageProperties,在AMQP协议中定义了14中properties,这些属性会随着消息一起发送)中设置 ...

  2. SPARK 创建新任务

    1.应用程序创建 SparkContext 的实例 sc 2.利用 SparkContext 的实例来创建生成 RDD 3.经过一连串的 transformation 操作,原始的 RDD 转换成为其 ...

  3. 做多了国际化项目,你怎么处理时区不同的各种blabla...问题

    我们做的的都是国际化大项目,今天发现了个大bug,没错!是时区不同引起的,如果你觉得这还不简单,这样,这样,再这样不就可以了吗?我只能呵呵了. 先来普及一下基础知识 : 1.地球分为24时区,北京位于 ...

  4. 3分钟利用TurnipBit制作电子时钟

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 TurnipBit(www.turnipbit.com)是一个面向青少年的开发板 ...

  5. python自动化运维五:paramiko

    p { margin-bottom: 0.25cm; line-height: 120% } a:link { } paramiko是基于python实现的SSH2远程安全连接,支持认证以及密钥方式, ...

  6. Spring MVC 快捷定义 ViewController

    WHY  :               为什么我们需要快捷定义 ViewController ? 在项目开发过程中,经常会涉及页面跳转问题,而且这个页面跳转没有任何业务逻辑过程,只是单纯的路由过程 ...

  7. 一个有意思的Python小程序(全国省会名称随机出题)

    本文为作者原创,转载请注明出处(http://www.cnblogs.com/mar-q/)by 负赑屃 最近比较迷Python,仿照<Python编程快速上手>8.5写了一个随机出卷的小 ...

  8. Codeforces Round #378 (Div. 2)-C. Epidemic in Monstropolis

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. HTML5新特性之WebRTC[转]

    原文:http://www.cnblogs.com/jscode/p/3601648.html?comefrom=http://blogread.cn/news/ 1.概述 WebRTC是“网络实时通 ...

  10. Samba服务安装及配置

    服务器环境:CentOS6.9 Linux 2.6.32-696.10.1.el6.x86_64 安装Samba服务 过程中会安装3个服务smb(文件.打印共享服务,使用139.445端口).nmb( ...