Implementation of stack, Data Structure & Algorithms

Assignment Help:

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)


Related Discussions:- Implementation of stack

Matrices multiplication, Write an algorithm for multiplication of two spars...

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Comp. sci algorithms, 1. develop an algorithm which reads two decimal numbe...

1. develop an algorithm which reads two decimal numbers x and y and determines and prints out wether x>y or y>x. the input values, x and y, are whole number > or equal to 0, which

Progrrame, how to write a code for for a company , for calculate the salary...

how to write a code for for a company , for calculate the salary pay

Branch and Bound method, give some examples of least cost branch and bound ...

give some examples of least cost branch and bound method..

Sorting algorithms, Sorting is significant application activity. Several so...

Sorting is significant application activity. Several sorting algorithms are obtainable. But, each is efficient for a specific situation or a specific kind of data. The choice of a

Avl tree, Example: (Single rotation into AVL tree, while a new node is inse...

Example: (Single rotation into AVL tree, while a new node is inserted into the AVL tree (LL Rotation)) Figure: LL Rotation The rectangles marked A, B & C are trees

Advanced data structures - splay trees, This is a unit of which targeted on...

This is a unit of which targeted on the emerging data structures. Red- Black trees, Splay trees, AA-trees & Treaps are introduced. The learner must explore the possibilities of app

What is gouraud shading, Gouraud Shading The faceted appearance of a La...

Gouraud Shading The faceted appearance of a Lambert shaded model is due to each polygon having only a single colour. To avoid this effect, it is necessary to vary the colour ac

The complexity of searching an element, The complexity of searching an elem...

The complexity of searching an element from a set of n elements using Binary search algorithm is   O(log n)

Construction of a binary tree , Q. Construct a binary tree whose nodes in i...

Q. Construct a binary tree whose nodes in inorder and preorder are written as follows: Inorder : 10, 15, 17, 18, 20, 25, 30, 35, 38, 40, 50 Preorder: 20, 15, 10

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd