Reverse order of elements on a slack, Data Structure & Algorithms

Q. Reverse the order of the elements on a stack S

   (i) by using two additional stacks

(ii) by using one additional queue.

Ans:      Let S be the stack having n number of elements. Now we need to reverse the elements of S (i) using the two additional stack S1 and S2

while not empty (S)

{       C=pop(S);



While not empty(S1)

{     C=pop(S1);



While not empty(S3)

{     C=pop(S3);



(ii) using one additional queue Q

while not empty (S)

{       C=pop(S);



While not empty(Q)

{     C=deque(Q);



Posted Date: 7/10/2012 3:11:04 AM | Location : United States

Related Discussions:- Reverse order of elements on a slack, Assignment Help, Ask Question on Reverse order of elements on a slack, Get Answer, Expert's Help, Reverse order of elements on a slack Discussions

Write discussion on Reverse order of elements on a slack
Your posts are moderated
Related Questions
Draw trace table and determine the output from the below flowchart using following data (NOTE: input of the word "end" stops program and outputs results of survey):  Vehicle = c

Link list representation of a circular queue is more efficient as it employs space more competently, of course with the added cost of storing the pointers. Program 7 gives the link

Q .  Write down the non-recursive algorithm to traverse a tree in preorder. Ans: T he Non- Recursive algorithm for preorder traversal is written below: Initially i

A binary tree is a special tree where each non-leaf node can have atmost two child nodes. Most important types of trees which are used to model yes/no, on/off, higher/lower, i.e.,

Define null values.  In some cases a particular entity might not have an applicable value for an attribute or if we do not know the value of an attribute for a particular entit

Write a function that performs the integer mod function. Given the previous functions you have implemented already, this one should be a piece of cake. This function will find the

1. Give both a high-level algorithm and an implementation (\bubble diagram") of a Turing machine for the language in Exercise 3.8 (b) on page 160. Use the ' notation to show the co

Deletion Algorithm for dequeue Step 1: [check for underflow]   If front = 0 and rear = 0   Output "underflow" and return Step 2: [delete element at front end]   If front

Example 3: Travelling Salesman problem Given: n associated cities and distances among them Find: tour of minimum length that visits all of city. Solutions: How several