container collection data structure

 

http://www.open-open.com/lib/view/open1474167415464.html

 

 

 

Basic container:

gather:

1.set: There is no relationship between elements, determinism, non-repetition, disorder.

 

Linear structure:

1. Linear table: One element after another, can be inserted or deleted at any position.

2. Team: First in, first out, only inserted at the tail, read at the head.

3. Stack: last in first out, only one end is allowed to insert and delete.

 

Tree:

1. Tree: A child node has only one parent node, and a parent node can have multiple child nodes.

2. Binary tree: A tree in which each node has at most two children.

 

grid:

1. Graph: Nodes can be connected arbitrarily.

 

Other containers or composite containers:

Hash table: Use the hash function to find the address of the value according to the value (the value and the address have a functional relationship, storage address = f (element value), for example: storage address = the square of the element value), if the address of the value conflicts, you can Use conflict resolution methods, for example: you can hang an address in the form of a linked list.

Index table: Extract some values ​​from an ordered linear table to form an index table (the values ​​of the index table are also ordered) for easy search.

Map: Mainly used to store key-value pairs. The keys are stored in a list, and the corresponding values ​​are stored in another list. The address of the value can be found by the address of the key. (For example: two arrays of the same size, one for keys and one for values, the subscripts of the keys and values ​​are the same)

 

How the container is stored:

Sequential storage: (the address space is continuous) (it is convenient to read the elements at the specified position, and it is troublesome to move the elements in sequence for insertion and deletion),

Chained storage: (The previous element has a pointer to point to the next element) (Reading the element at the specified position requires searching for trouble from the beginning, and inserting and deleting only need to move the pointer to facilitate.).

-------------------------------------------------------------------------------------------------------------------------------------

1.1

 1.2


 

 

1. Collection set

HashSet: Hash table stores set, and elements cannot be repeated.

-------------------------------------------

TreeSet:元素是排序,默认是自然顺序。也可自己传Comparator

-------------------------------------------

LinkedHashSet:元素有插入的顺序。

------------------------------------------------------------------------------------

 

2.list,queue,stack(线性表,队,栈)

lis(线性表)t:

Arraylist:是线性存储,就是用数组实现的,它会动态增加他的50%容量。善于查找。

LinkedList:是链式存储,善于增加删除。使用时LIst list=new LinkedList();

--

vector:和ArrayList基本一样,它会动态增加他的翻倍容量,也可设置增长因子,只是它是线性安全的。

--

并发包的:

------------------------------------------------------------------------------------

queue(队):

LinkedList:它实现Queue接口。使用时:Queue queue = new LinkedList();

--

并发包的:

-------------------------------------------

PriorityQueue:带有先级的队列,每次从队列中取出的是具有最高优先权的元素。构造时需要传Comparator,如果没有数字默认是小的在队列头,字符串则按字典序排列。

------------------------------------------------------------------------------------

 栈:

--

stack:线性安全的栈。数组现实的。

------------------------------------------------------------------------------------

deque(双端队列):技能实现队的功能又能显示栈的功能。:

ArrayDeque:是线性存储,就是用数组实现的双端队列。

LinkedList:它实现Deque接口。使用时:Deque deque= new LinkedList();

--

并发包的: 

------------------------------------------------------------------------------------

 

3.map

HashMap:用哈希表的方法存储键值对。允许key为null

--

HashTable:和nashmap相似,只是它是线程安全的。不允许key为null

-------------------------------------------

TreeMap:是排序的容器,用iterator输出是排序好的,默认是按自然顺序,也可构造时传Comparator自定义顺序,键底层是二叉树数据结构。

-------------------------------------------

LinkedHashMap:能保持插入的顺序。在用Iterator遍历LinkedHashMap时,先得到的记录肯定是先插入的。实体虽然是以Hash的顺序存放在Hash表中,但是实体之间却用链表的形式保持了存入的先后关系。

 

-------------------------------------------------------------------------------------------------------------------------------------

ComParable是比较接口compareTo(T another);是需要比较的类自身实现。类自身实现。

ComParator也是比较接口compare(T lhs, T rhs);是可以传一个类的两个实例进行比较。类外实现

 

Collections:集合类的,排序或其他功能工具。

Arrays:普通数组(int[] a)的,排序或其他功能的工具。

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326759215&siteId=291194637