java特征
inheritance
the root object class
abstract classes抽象类方法
interfaces接口
genetics泛型
线性数据结构
ps:An abstract data type (ADT) is a set of objects together with a set of operations. Abstract data types are mathematical abstractions; nowhere in an ADT’s defifinition is there any mention of how the set of operations is implemented.
抽象数据类型(ADT):带有操作的数据集合
数组array
In case of a linked list having n elements, we need to travel through every node of the list to add the element at the end of the list. Thus asymptotic time complexity is θ(n).
We know the head node in the given linked list. Insertion and deletion of elements at the front of the linked list completes in O (1) time whereas for insertion and deletion at the last node requires to traverse through every node in the linked list. Suppose there are n elements in a linked list, we need to traverse through each node. Hence time complexity becomes O(n).
栈stack
特点:结构清晰,先进后出。
operations:push、pop(空栈没有,可以来判断是否为空)、top(空栈没有,可以来判断是否为空)
Process of inserting an element in stack is called push.
In a stack, if a user tries to remove an element from empty stack it is called underflow.Underflow occurs when the user performs a pop operation on an empty stack. Overflow occurs when the stack is full and the user performs a push operation. Garbage Collection is used to recover the memory occupied by objects that are no longer used.
Pushing an element into stack already having five elements and stack size of 5, then stack becomes overflow.
That there is a Sequential entry that is one by one is the meaning of that entries in a stack are “ordered”.In stack data structure, elements are added one by one using push operation. Stack follows LIFO Principle i.e. Last In First Out(LIFO).
Wjen data Transfer between two asynchronous process,you may not use a stack.Data transfer between the two asynchronous process uses the queue data structure for synchronisation. The rest are all stack applications.
In the entire parenthesis balancing method when the incoming token is a left parenthesis it is pushed into stack. A right parenthesis makes pop operation to delete the elements in stack till we get left parenthesis as top most element. 3 elements are there in stack before right parentheses comes. Therefore, maximum number of elements in stack at run time is 3.
用单链表实现栈功能:
对列queue
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a queue.Linear list of elements in which deletion is done at front side and insertion at rear side is called Queue. In stack we will delete the last entered element first.
The data structure required for Breadth First Traversal on a graph is queue. In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices which are unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent vertex list will be considered to add further unvisited vertices of the graph. To get first unvisited vertex we need to follows First In First Out principle. Queue uses FIFO principle.
Circular Queue is also known as Ring Buffer.Circular Queue is also called as Ring Buffer. Circular Queue is a linear data structure in which last position is connected back to the first position to make a circle. It forms a ring structure.
When Rear = MAX_SIZE – 1, there will be no space left for the elements to be added in queue. Thus queue becomes full.
用单链表实现队功能:
package chp3.ex03.que32;
public class SingleQueue<AnyType> {
private Node<AnyType> front, rear;
SingleQueue(){
front = null;
rear = null;
}
public Node<AnyType> getFront(){
return front;
}
public Node<AnyType> getRear(){
return rear;
}
void enqueue(AnyType x) {
Node<AnyType> p = new Node<AnyType>(x, null);
if (rear != null) {
rear.next = p;
rear = p;
}
else {
front = p;
rear = p;
}
}
AnyType dequeue() {
AnyType temp = front.data;
Node<AnyType> p = front;
if (front.next == null) {// only 1 node
front = null;
rear = null;
}
else
front = front.next;
return temp;
}
private class Node<AnyType>{
AnyType data;
Node<AnyType> next;
Node(){
this(null, null);
}
Node(AnyType x){
this(x, null);
}
Node(AnyType x, Node<AnyType> p){
data = x;
next = p;
}
}
}
链表linked list
The ‘next’ pointer points to null only when the list is empty, otherwise it points to the head of the list. Every node in circular linked list can be a starting point(head).
我们将大小为0的特殊列表称为空列表。
数据链表(array list)
频繁查找用数组链表,频繁插入撤销用单向链表
单向链表(Simple Linked Lists)
查找数据要挨个执行访问,数据后面只跟一个指针。
双向链表(Doubly Linked Circular Lists)
A doubly linked list has two pointers ‘left’ and ‘right’ which enable it to traverse in either direction. Compared to singly liked list which has only a ‘next’ pointer, doubly linked list requires extra space to store this extra pointer. Every insertion and deletion requires manipulation of two pointers, hence it takes a bit longer time. Implementing doubly linked list involves setting both left and right pointers to correct nodes and takes more time than singly linked list.
频繁访问数据时优势明显,一个数据有左右两个指针。
非线性数据结构
Binomial Queues二项队列
二项树的集(二项树:There is at most one binomial tree of every height. A binomial tree of height 0 is a one-node tree; a binomial tree, Bk, of height k is formed by attaching a binomial tree, Bk−1, to the root of another binomial tree, Bk−1. )
合并:高度一致的二项树合并
删除1.删除根节点值最小的二项树,剩下二项树集合成为新的二线队列H'
2.去掉删除的二项树节点,成为H''
3.合并H'与H''