数据结构与算法--链表
2023-09-14 08:59:01 时间
首先链表分三种:
单链表,双链表,循环单链表
写个例子说明列表的创建和遍历:
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 相关文章
- [牛客经典必刷算法题] LC5-链表的插入排序
- 刷LeetCode链表之前你需要掌握的设置结点技巧C++
- LintCode 链表排序[通俗易懂]
- c 语言实现链表反转(超详细,有手就行)
- Go 数据结构和算法篇(一):链表
- 从尾到头打印链表(python题解)
- 基本算法:逆转链表
- 高频算法题-环形链表 II
- 数据结构实验之链表九:双向链表(SDUT 2054)
- BAT算法面试题(12)--环形链表(哈希表法)
- BAT算法面试题--环形链表(哈希表法)
- LeetCode每日一题之817题链表组件
- 算法-删除链表中重复的结点详解编程语言
- 算法-链表中环的入口结点详解编程语言
- 算法-复杂链表的复制详解编程语言
- LeetCode 0109 有序链表转换二叉搜索树详解编程语言
- 算法练习之x的平方根,爬楼梯,删除排序链表中的重复元素, 合并两个有序数组详解编程语言
- Linux内核之美:链表表现力(linux内核链表)
- Oracle中优化链表结构的实现(oracle中链表结构)
- C语言实现输出链表中倒数第k个节点