数据结构与算法--链表
2023-09-14 09:00:31 时间
首先链表分三种:
单链表,双链表,循环单链表
写个例子说明列表的创建和遍历:
public class LinkList { private Node head; private Node current; private void add(int data) { if(head == null) { head = new Node(data, null); current = head; } else { //创建新的结点 Node node = new Node(data, null); //新创建的节点和列表进行关联 current.next = node; //移动当前链表的索引位置 current = node; } } private void print(Node node) { if(node == null) { return; } Node current = node; while(current != null) { System.out.println(current.data); current = current.next; } } /** * @ClassName: Node * @Description: TODO(定义Node数据类型) */ classNode { int data; Node next; public Node() { } public Node(int data, Node next) { super(); this.data = data; this.next = next; } } public static void main(String[] args) { LinkList list = newLinkList(); for(int i = 0; i < 10; i++) { list.add(i); } list.print(list.head); } }
运行结果:
0
1
2
3
4
5
6
7
8
9 相关文章
- 缓存LRU算法——使用HashMap和双向链表实现
- LRU算法list链表实现
- 经典算法题每日演练——第二十一题 十字链表
- 数据结构与算法JavaScript (三) 链表
- 数据结构与算法--链表
- 重新整理数据结构与算法——环形链表[五]
- LeetCode(86):分隔链表
- 【学习总结】小象学院-算法面试课程1-链表
- 数据结构和算法03 之链表
- Algorithm:C++语言实现之链表相关算法(单链公共结点问题、一般LCA、括号匹配、最长括号匹配、逆波兰表达式Reverse Polish Notation、直方图矩形面积、收集雨水问题)
- Algorithm:C++语言实现之链表相关算法(链表相加、链表的部分翻转、链表划分、链表去重、重复元素全部删除)
- 114. 二叉树展开为链表-C语言dfs算法解题
- [LeetCode] 382. 链表随机节点 ☆☆☆(随机算法:蓄水池抽样)
- 一步一步写算法(之单向链表)
- 《数据结构与算法分析》学习笔记(三)——链表ADT
- 企业链表List
- 【LeetCode】23. 合并K个升序链表
- 【数据结构与算法】什么是双向循环链表?以及实现过程
- 【数据结构与算法】什么是双向链表?并用代码手动实现一个双向链表
- 数据结构和算法 二、数组和链表
- 数据结构和算法 十、链表的类型