#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. [mysql使用(1)] 64位Linux下安装mysql-5.7.13-linux-glibc2.5-x86_64

    由于公司临时让将Oracle的数据移植到mysql上面,所以让我在公司服务器上面安装一下mysql.下面就是我的安装过程以及一些错误解决思路.其实对于不同版本安装大体都有差不多. 1. 从官网下载 m ...

  2. 【ASP.NET MVC 学习笔记】- 15 Unobtrusive Ajax

    本文参考:http://www.cnblogs.com/willick/p/3418517.html 1.Unobtrusive Ajax允许我们通过 MVC 的 Help mothod 来定义 Aj ...

  3. Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...

  4. 【hihoCoder】#1039 : 字符消除 by C solution

    #1039 : 字符消除 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消 ...

  5. vue之地址栏#号问题

    mode的两个值 histroy:当你使用 history 模式时,URL 就像正常的 url,例如 http://jsapng.com/lms/,也好看! hash:默认'hash'值,但是hash ...

  6. 版本控制之二:SVN的初步使用(转)

    转自http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407979.html 上一篇介绍了VisualSVN Server和Tortoise ...

  7. enum(枚举类型)

    可以使用枚举类型声明代表整数常量的符号名称. 通过enum,创建一个新类型,并指定它可以拥有的值.(就像平常用一个整形变量,我们指定它等于0的时候代表什么,1呢,2呢...而通过枚举,就增加了程序的可 ...

  8. 初探 ELK - 每天5分钟玩转 Docker 容器技术(89)

    在开源的日志管理方案中,最出名的莫过于 ELK 了.ELK 是三个软件的合称:Elasticsearch.Logstash.Kibana. Elasticsearch一个近乎实时查询的全文搜索引擎.E ...

  9. linux GCC 编译多个.c/.h文件

    基本认识: #include <xxx>:首先去系统目录中找头文件,如果没有在到当前目录下找.像标准的头文件 stdio.h.stdlib.h等用这个方法. #include " ...

  10. 哈尔滨理工大学第六届程序设计团队 E-Mod

    /* 成功水过,哈哈哈,可能数据水吧 */ #include <stdio.h> #include <algorithm> #include <string.h> ...