[Description] Given a unsort linked list, delete all the duplication from them, no temporary space permission.

[Thought] Set two points, from head to tail, scaning all linked list. O(n^2).

[Implementation] C code:

 #include<stdio.h>

 typedef struct linkedList
{
int data;
struct linkedList* next;
} llist; llist** delDupli(llist **head)
{
// two point, t1 for target, t2 for mover.
llist *t1, *t2;
t1=t2=*head;
while(t1->next != NULL)
{
// ajust t2 from t1!
t2=t1;
while(t2->next != NULL)
{
// check if they are the same
if(t2->next->data == t1->data)
{
// move t2->next; note: no memory free here.
t2->next=t2->next->next;
}
// after move out node, check if t2 is already the last one.
if(t2->next != NULL)
{
t2=t2->next;
}
}
t1=t1->next;
}
return head;
} int addValue(llist **head, int val)
{ llist *pnode;
llist *t=*head;
// apply memory for linked list.
pnode=(llist*)malloc(sizeof(llist));
if(NULL==pnode)
{
return ;
}
pnode->data=val;
pnode->next=NULL;
// first node
if(NULL==*head)
{
*head=pnode;
return ;
}
// move temp point to the last node
while(t->next != NULL)
{
t=t->next;
}
t->next=pnode;
return ;
} // out put data, be careful about the first node.
int printList(llist **head)
{
llist *t=*head;
printf("%d, ",t->data);
while(t->next != NULL)
{
t=t->next;
printf("%d, ",t->data);
}
printf("\n");
return ;
} int main()
{
int a[]={,,,,,,,,,,,,};
llist *head=NULL;
int i; for(i=;i<(sizeof(a)/sizeof(a[]));i++)
{
// printf("a[i]:%d\n",a[i]);
addValue(&head,a[i]);
// printList(&head);
}
printf("Initial linked list:\n");
printList(&head);
printf("After deleting:\n");
printList(delDupli(&head));
}

[002] delete_duplication_of_linked_list的更多相关文章

  1. 【GoLang】GO语言系列--002.GO语言基础

    002.GO语言基础 1 参考资料 1.1 http://www.cnblogs.com/vimsk/archive/2012/11/03/2736179.html 1.2 https://githu ...

  2. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数002·AI人工智能

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数002·AI人工智能 AI人工智能:包括knn.gmm.svm等 为方便阅读,在不影响说明的前提下,笔者对函数进行了 ...

  3. php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动

    php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动 每个人机器不一样,我手头是个air book,查了一下现在最好在mac下,用mamp, mamp百科介绍 , ...

  4. 【面试题002】java实现的单例模式,c++实现单例模式,实现禁止拷贝

    [面试题002]java实现的单例模式,c++实现单例模式,实现禁止拷贝  一 c++实现单例模式 保证一个类,在一个程序当中只有一个对象,只有一个实例,这个对象要禁止拷贝,注意这里要区别于java. ...

  5. [反汇编练习] 160个CrackMe之002

    [反汇编练习] 160个CrackMe之002. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  6. 002 Spring Restful案例

    1:工程结构 需要注意的是需要额外导入以下三个包: jackson-annotations-2.6.1.jar jackson-core-2.6.1.jar jackson-databind-2.6. ...

  7. python----特性002

    python特性002:特性是可继承的 #!/usr/local/python3.5/bin/python3 class Person(object): def __init__(self,name) ...

  8. python解释器内建函数002

    001.dict 函数来创建字典 #!/usr/bin/python #!coding:utf-8 if __name__ == "__main__": dct001=dict(h ...

  9. Python[小甲鱼-002用Python设计第一个游戏]

    –Code——————————————————————- print("----------第一个小游戏----------") temp = input("猜一下我现在 ...

随机推荐

  1. display:table的几个妙用:垂直居中、浮动……

    一.为什么不用table系表格元素? 目前,在大多数开发环境中,已经基本不用table元素来做网页布局了,取而代之的是div+css,那么为什么不用table系表格元素呢? 1.用DIV+CSS编写出 ...

  2. 第202天:js---原型与原型链终极详解

    一. 普通对象与函数对象 JavaScript 中,万物皆对象!但对象也是有区别的.分为普通对象和函数对象,Object .Function 是 JS 自带的函数对象.下面举例说明 var o1 = ...

  3. BZOJ 1565 植物大战僵尸(拓扑排序+最大权闭合子图)

    图中的保护关系就类似于最大权闭合子图.即你想杀x,你就一定要杀掉保护x的点,那么把x向保护它的点连边.那么题目就转化成了最大权闭合子图的问题. 但是这个图有点特殊啊... 考虑有环的情况,显然这个环以 ...

  4. BZOJ4887 Tjoi2017可乐(动态规划+矩阵快速幂)

    设f[i][j]为第i天到达j号城市的方案数,转移显然,答案即为每天在每个点的方案数之和.矩乘一发即可. #include<iostream> #include<cstdio> ...

  5. [洛谷P5137]polynomial

    题目大意:求:$$\sum\limits_{i=0}^na^{n-i}b^i\pmod{p}$$$T(T\leqslant10^5)$组数据,$a,b,n,p\leqslant10^{18}​$ 题解 ...

  6. [JLOI2011]飞行路线 最短路

    题面 题面 题解 这题不是很难,因为删代价的次数不多,因此我们只需要将最短路中的状态加一维表示已经删了几次,再转移即可 #include<bits/stdc++.h> using name ...

  7. C++操作Windows WIFI

    原文链接地址:https://blog.csdn.net/just_do_1122/article/details/78031024 实现功能     无线网卡列表     无线热点扫面     无线 ...

  8. SCWS中文分词,demo演示

    上文已经讲了关于SCSW中文分词的安装配置,本节进入demo演示: <?php header('Content-Type:text/html;charset=UTF-8'); echo '< ...

  9. go日期时间函数+常用内建函数+错误处理

    日期时间函数 // 时间日期函数包 import "time" // 1. 当前时间 time.Now()-->time.Time类型 // 2. now:=time.Now ...

  10. spring集成webSocket实现服务端向前端推送消息

    原文:https://blog.csdn.net/ya_nuo/article/details/79612158 spring集成webSocket实现服务端向前端推送消息   1.前端连接webso ...