数据结构之链表
来源:互联网 发布:河北保定seo 编辑:程序博客网 时间:2024/06/05 00:22
数据结构——链表
删除链表中重复数据
使用hashtable
- 时间复杂度低,需要额外的存储空间
public void delete(Node node) { Hashtable<Integer, Integer> table = new Hashtable<Integer,Integer>(); Node tmp =head; Node pre =Null; while (tmp != null) { if (table.containsKey(tmp.data)) { pre.next=tmp.getNextSibling(); } else { table.put(tmp.data, 1); pre = tmp; } } tmp=tmp.getNextSibling();}
- 时间复杂度低,需要额外的存储空间
使用双重循环遍历
- 时间复杂度高,不需要额外的空间
public void delete(Node node) { Node p = head; while (p !=null) { Node q =p; while (q.next != null) { if (p.data=q,next.data) { q.next = q.next.next; }else { q=q.next; } } p=p.next; }}
- 时间复杂度高,不需要额外的空间
阅读全文
0 0
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- Linux总结笔记10-搭建DHCP服务
- 关于grafana的安装和反向代理配置
- zendstudio 实现多种配色方案(sublime)
- [BZOJ 2820]YY的GCD:莫比乌斯反演
- maven resin 热部署
- 数据结构之链表
- java基础篇(七)——三大特性之封装
- 拓扑排序(Topological Sorting)
- 操作系统(三) CPU调度
- javaweb开发
- Linux总结笔记11-搭建ISCSI网络存储
- Netty之Channel的继承关系
- mac vpn不支持pptp解决方法
- c++读写加速语句