首页 > 编程语言 >算法经常用到的数据结构

算法经常用到的数据结构

时间:2023-01-21 00:11:38浏览次数:34  
标签:ListNode val int 用到 next 算法 new 数据结构 public

:先进后出

Stack<Integer> stack = new Stack<>();
// 推荐
Deque<Integer> stack1 = new ArrayDeque<>();
// pop() 删除并返回栈顶的值
// peek()返回栈顶端的值,不删

类似于HastTable 和 HashSet的区别,HashTable是线程安全的,HashSet是非线程安全的

队列:先进先出

//定义一个队列
Queue<String> queue = new LinkedList<String>(); 
// 添加 add()、offer()
// 删除:remove() poll()
// 不删除:element()、peek()

链表:非连续

// 自定义一个 链表
public class ListNode { public int val; public ListNode next; public ListNode() {} public ListNode(int val) { this.val = val; } public ListNode(int val, ListNode next) { this.val = val; this.next = next; } }

  

TreeSet 有序 不重复。key不能为空,value不能为null

(只要是有Tree 就是有序。只要是有Set就是不重复)

 

标签:ListNode,val,int,用到,next,算法,new,数据结构,public
From: https://www.cnblogs.com/hai08/p/17063421.html

相关文章