01 Fun stacks and queues data structure _03_

Stack:

Stack Overview:

 

Although it looks like it is only a subset of the array, but this stack structure set up for computer logic have this very, very big role.

 

Push the stack:

 

 

Stack is a last-out (FILO First in Last Out) structure.

 

Application stack 01: undo:

 

 

 

02 application stack: the program calls the system stack:

It helps us to understand better understand recursion! !

 

 

 

At this time, the system will record the stack:

 

A2 means a second row A to perform the function.

 

The same system will continue to press the stack! ! !

 

 

 

When a C function is finished, our computers do not know who carried out this,

At this point it would look at the contents of the system stack,

It found B2, so restart from B2. (Will also pop B2)

When B is also a function of time is finished, the computer system will look stack, found A2

So, it will begin from A2. (Will also pop-A2)

A function is also performed when completed, the system stack is empty. So the function is finished! ! !

 

This process is recursive great help to understand, will be behind the content on recursion. 

 

 

Stack implementation:

Stack five basic operations:

 

Which peek () Some languages ​​prefer to call it top ()!

 

 

Here that one kind of stack underlying implementation (say another later):

The back of the queue would say that two kinds of different underlying implementation.

 

Code design mode:

To design an interface, and then use ArrayStack to achieve it.

 

 

Specific code as follows:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zach0812/p/11827922.html