Difference heap, stack and stack

Heap (heap): heap data structure is a tree after sorted, each node has a value.

Stack (stack): It is a LIFO data structure having properties, that is taken after the first storage, taken after the first storage. (PS: quite brick walls - latecomers catch up on foot.)

1, the mode of application

heap: programmer application, and specify the size.

stack: the distribution system.

2, application efficiency

Read:

heap: more efficient, faster, but the programmer can not control it.

stack: memory allocated by new, fast, and relatively low efficiency, and easily fragmented, but the operation is the application programmer, flexible, and easy to use.

3, the stored data type

stack: the stored value type, i.e. fixed length data storage. For example: integer, character, structure, Boolean, enumerated and so on. Each program is executed has its own stack, other programs can not access the stack.

heap: storing a reference type

Third, the relative term.

1, push (push, push): expressed push, the data is placed on the stack, into the top of the stack, there are last-out features!

2, clear the stack : All empty stack.

3, the stack: with POP indicated that it is the opposite and push the concept that takes the data out from the stack. Removed from the stack when the stack.

 

Visualize explanation: There are two floor, holding a brick, continue up the levy, it is pushed onto the stack. Remove the bricks demolition, brutally inflicted to buildings bungalow, it is a stack. Then, if this building is not pleasing to the eye to see, directly to the bombing, the kind of ash is not left, called clear stack.

 

Attention to the problem : push: the need to consider whether the full stack, such as a building according to the capacity of the foundation, the current height reached the limit, then it can not continue to build up.

          Stack clear: the need to consider whether the stack is empty, empty stack, do not need to clear the stack.

          Stack: Each can only be popped out of the top of the stack. (PS: I think of the stack is not gotta leave something, if nothing left, not become clear the stack)

 

4, a stack overflow: is a partial block size regardless of the stack allocated to the data block write data is too much, leading to cross-border data, the results covering the old stack data. (PS: a bit like an array subscript cross-border issues)

. For example: class, interface, and the like array.

Guess you like

Origin www.cnblogs.com/zhuyeshen/p/12125248.html