Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Data structures using Pseudocode with C

Posted on 2003-02-20
Medium Priority
795 Views
Imagine we have TWO  empty stacks of integers , s1  and s2  . Draw a picture of each stack after the following operation.

problem

pushStack  ( s1,   3 );
pushStack   ( s1,  5 );
pushStack   ( s1,  7 );
pushStack   ( s1,  9 );
pushStack   ( s1,  11);
pushStack   ( s1,  13);
while  ( !emptyStack  ( s1) )
{
popStack  ( s1,  x);
popStack   ( s1,  x);
pushStack  ( s2,  x);
}

I am not sure of the meaning of empty stacks of intergers. The ! is a logical operator . I have tried to work this on paper but to no avail. I do not have a complier and not sure how I would write this to C prog.
any help would be great. Is there something missing in this problem or is it complete to solve??? [ if you do have problems and cant get it please let me know if there is someone else that can help] tho I think you guys can help me. If you could try and explain to me the drawing that you come up with.
jerry
0
Question by:jhook53
• 3
• 2

LVL 85

Expert Comment

ID: 7990907
pushStack  ( s1,   3 );
/* s1={3} */
pushStack   ( s1,  5 );
/* s1={3,5} */
pushStack   ( s1,  7 );
/* s1={3,5,7} */
pushStack   ( s1,  9 );
/* s1={3,5,7,9} */
pushStack   ( s1,  11);
/* s1={3,5,7,9,11} */
pushStack   ( s1,  13);
/* s1={3,5,7,9,11,13} */
while  ( !emptyStack  ( s1) )
{
popStack  ( s1,  x);
/* s1={3,5,7,9,11} ; s1={3,5,7} ; s1={3} */
popStack   ( s1,  x);
/* s1={3,5,7,9}    ; s1={3,5}   ; s1={}; */
pushStack  ( s2,  x);
/* s2={11}         ; s2={11.7}  ; s2={11,7,3} */
}
/* s1={}; */
/* s2={11,7,3} */
0

LVL 44

Accepted Solution

Arthur_Wood earned 200 total points
ID: 7990949
think of a STACK of Pancakes.  Each time you pushStack, you add another pancake to the TOP of the stack.  Each time you popStack, you take the remaining TOP pancake off the stack(if there are any to remove).

An emptyStack is just that, a Stack of Pancakes, with NO PANCAKES in the stack.

In the above, you have pushed 6 NUMBERS, one after the other onto the stack, which would then look like this (the top number would be

13
11
9
7
5
3
----- this is s1

then you remove two numbers form Stack 1, and push the SECOND value that you remove, onto Stack 2, and repeat until Stack1 is empty:

pass 1:

9
7
5
3             11
--- s1       --- s2

pass 2:

5            7
3            11
---  s1      ---  s2

pass 3:

3
7
11
--- s1      --- s2

AW

0

LVL 44

Expert Comment

ID: 7993830
ozo,
correct me if I am wrong (and that is always possible) but a STACK is LIFO (Last In First Out), while a QUEUE is FIFO(First In First Out)...

AW
0

LVL 85

Expert Comment

ID: 7996024
Correct, a STACK is Last In First Out, while a QUEUE is First In First Out
0

LVL 44

Expert Comment

ID: 7999515
ozo, so then YOUR depiction would be a QUEUE and NOT a Stack???

pushStack  ( s1,   3 );
/* s1={3} */
pushStack   ( s1,  5 );
/* s1={3,5} */

Shouldn't that be:

pushStack  ( s1,   3 );
/* s1={3} */
pushStack   ( s1,  5 );
/* s1={5,3} */

since 5 has been pushed onto the HEAD(FIRST POSITION) of the Stack?

AW
0

Expert Comment

ID: 9447609
jhook53:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project
###### Suggested Courses
Course of the Month10 days, 9 hours left to enroll