blogger Indonesia

Follow judhyns blog

THE CONCEPT OF STACK

Introduction

A stack is memory in which values are stored and retrieved in "last in first out" manner by using operations called push and pop.

Program

Suppose you want to insert values in a stack and retrieve values from the stack. The operations would proceed in the following manner:

Click To expand

Explanation

  1. Initially, the stack is empty. When you start push A, A is placed in the stack.

  2. Similarly, push B and push C put these elements in the stack; the last element pushed is C.

  3. The pop operation takes the topmost element from the stack. Thus the element C, which was put in last, is retrieved first. This method is called last-in first-out (LIFO).

  4. The push D operation puts element D in the stack above B.

  5. Thus push puts the element on the top of the stack and pop takes the element from the top of the stack. The element A which is pushed is the last element taken from the stack.

Point to Remember

The last-in first-out retrieval from the stack is useful for controlling the flow of execution during the function call.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |