主要是作为JAVA初学者对于常用数据结构的一些理解和总结
List
线性表
ArrayList
顺序表(动态数组)–元素不限于int等
属性
- elementData-储存数据
- size-储存个数
函数
- 构造函数-ArrayList()
- 无参数-(initial capacity 10)
- initial size(实现能够判断数组大小)
- 拷贝构造函数(???此处关于collection相关知识https://www.cnblogs.com/skywang12345/p/3308556.html) https://zhuanlan.zhihu.com/p/27873515
- add(int index,E element)
- remove(int index)
- get(index)
特性
- 非线程安全(???)
- 关于equal -https://zhuanlan.zhihu.com/p/27562748
LinkedList
链式表
(leetcode里面题目中大多数使用的是单链表-单纯val&next,而JAVA中的LinkedList 则指的是双向链表,对于用法要进行一定的区分)
Set
集合
Map
Stack
Queue
队列是一种特殊的线性表-FIFO
- 新建(LinkedList类是实现类,它实现了Queue接口)-
Queue<Object> queue = new LinkedList<>()
- 添加元素
queue.offer(element)
- 返回元素(同时删除)
element = queue.poll()
- 返回元素(不删除-空队列返回
null
)element = queue.peek()
*判断是否为空queue.isEmpty()
import java.util.LinkedList;
public class Queue {
public static void main(String[] args)
{
LinkedList<String> queue = new LinkedList<String>(); // LinkedList是实现Queue接口的,所以LinkedList可以用Queue接口的方法
queue.offer("a"); //offer 为入队
queue.offer("b");
while(!queue.isEmpty())
{
System.out.println(queue.poll()); //poll 为出队
}
}
}