结构综述
节点 Node
class Node {
int val;
Node next;
...
}
链表 Linked List
class LinkedList {
Node head;
Node tail;
int size;
...
}
堆栈 Stack
由数组实现
数组 + top
class Stack {
int capacity;
int top;
int[] array;
...
}
由链表实现
class Stack {
Node top;
...
}
队列 Queue
由循环数组实现
class Queue {
int front, rear, size;
int capacity;
int[] array;
...
}
由链表实现
class Queue {
Node Front;
Node rear;
...
}
哈希表 HashMap
class HashNode {
String key;
Integer value;
HashNode<String, Integer> next;
}
class HashMap {
private ArrayList<HashNode<String, Integer>> bucketArray;
private int numBuckets;
private int size;
public HashMap() {
bucketArray = newArrayList<>();
numBuckets = 10;
size = 0;
for (int i = 0; i < numBuckets; i++) {
bucketArray.add(null);
}
}
...
}
树 Tree
节点
class TreeNode {
TreeNode left;
TreeNode right;
int value;
...
}
排序二叉树 Binary Search Tree
class BTS {
private TreeNode root;
...
}
优先队列 PriorityQueue
节点
class PriorityNode {
int value;
int priority;
PriorityNode next;
...
}
由链表实现
class PriorityQueue {
PriorityNode head;
...
}
堆 Heap
由数组实现
class MaxHeap {
int capacity;
int size;
int[] array;
...
}
图 Graph
由矩阵实现
int[][] matrix;
由链表()实现
class ListGraph {
// ArrayList<ArrayList<Integer>> 在概念上可以被看作是一个链表的链表,实际上它更类似于数组的数组,即一个动态重新分配的数组。
ArrayList<ArrayList<Integer>> graphs;
public ListGraph(int v) {
graphs = newArrayList<>(v);
for (int i=0; i<v; i++) {
graphs.add(newArrayList<>());
}
})
}