before programming a problem solution those


Before programming a problem solution those employees a stack, we have to decide how to represent a stack by using the data structures which exist in our programming language. Stacks might be represented in the computer in several ways, usually by means of a one-way list or a linear array. Each of the approach has its advantages & disadvantages. Generally a stack is implemented with two essential operations - push & pop. Push means to add an item on to stack. The push algorithm is sown in Figure.

Here, tos is a pointer which indicates the position of top most items into the stack. Stack is represented through the array arr and MAXSTACK represents the maximum possible number of elements into the stack. The pop algorithm is shown in Figure

Step 1: [test out for stack overflow]

if tos >=MAXSTACK

print "Stack is overflow" and exit

Step 2: [Increment the pointer value through one]

tos=tos+1

Step 3: [Add the item]

Step 4: Exit

arr[tos]=value

The pop operation eliminates the topmost item from the stack. After elimination of top most value tos is decremented by 1.

Step 1: [test out whether the stack is empty]

if tos = 0

print "Stack is underflow" and exit

Step 2: [Elimiante the top most item] value=arr[tos] tos=tos-1

Step 3: [Return the item of the stack]

return(value)

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: before programming a problem solution those
Reference No:- TGS0413455

Expected delivery within 24 Hours