Algorithm Queue & Stack

Nov 15, 2015 at 4:26pm
What would be the contents of the queue Q1?
The data are 5, 7, 12, 4, 0, 4, 6, 8, 67, 34, 23, 5, 0, 44, 33, 22, 6, 0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  BEGIN 
Create Queue Q1 
Create Stack S1 
 WHILE (not end of file)
 GET aNumber
IF (aNumber is not 0) 
pushStack (S1, aNumber) 
ELSE 
popStack (S1, x) 
popStack (S1, x) 
WHILE (not emptyStack (S1))
 popStack (S1, x)
 enQueue (Q1, x)
 ENDWHILE 
ENDIF
 ENDWHHILE 
END 
Last edited on Nov 15, 2015 at 4:27pm
Topic archived. No new replies allowed.