How to convert Stack in to Queue and v varsa ? c with data structure.

Questions by manojchambarge

Showing Answers 1 - 4 of 4 Answers

abhi1983

  • Jun 26th, 2006
 

Had it been vice versa queue to stack it would have been done easily by keeping the front pointer fixed.

Simply saying by having one more function in the implementation part.

But if you want to have a queue from a stack ... i think you might need to change the structure itself again it would end up as a queue itself ...

or use two stacks ;-)

  Was this answer useful?  Yes

abhimanipal

  • Jul 30th, 2009
 

Converting queue to stack. This basically means make a First in first out structure a last in first out structure. This is done by adding items in reverse
1
1<-2
1<-2<-3
1<-2<-3<-4

The other way around is tough. Making a last in first out structure a first in first out. This can be done by emptying the stack each time an item has to be added
1... Empty the stack. Put 2 then put 1
1,2....Empty the stack. Put 3 then put 2 then put 1

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions