Pushed and popped law

1. derived from

jvm heap is mainly used to keep objects, such as Object obj = new Object (), obj is present jvm stack, the stack is used to keep the member properties, each thread has a separate stack, front the obj will also save in a stack, but the object is not saved, but obj memory address of the heap. When no objects in the heap stack pointer to it, will be recovered by recovering the access speed GC garbage, the stack is greater than the stack register is less than, but must have a size and life cycle.

2. push the stack rules

Last-out, and then the stack after stack is not necessarily all, can not stack finished first out stack

3. Any element behind the pull element must satisfy two rules

1. In the original sequences (i.e. stack sequence) sequentially smaller than the stack of elements, must be reverse

2. In the original sequences (i.e. stack sequence) sequentially stack a large element ratio out, order does not matter

3. Stack element indicates that all elements of the stack back out

12345 such that the stack, the stack following two possible ways:

a. 1 5 4 3 2 1,1 elements look behind the first element of each of a large than this, it does not matter what order, look at the back of the second element is smaller than this number of elements 5,5, We must follow the reverse order, while 432 follow the reverse order, so no problem. . .

b. 4 3 5 1 2 4,4 The look behind the first element is smaller than it is 312, and this 12 is not significantly reverse order, i.e. in reverse order, it is problematic. When the surface of questions after the encounter the stack sequence, can be selected for a sub-minute.

Guess you like

Origin www.cnblogs.com/javalisong/p/12187605.html
law