?
Solved

Data structures using Pseudocode with C

Posted on 2003-02-20
7
Medium Priority
?
737 Views
Last Modified: 2010-04-17
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
Comment
Question by:jhook53
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 84

Expert Comment

by:ozo
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

by:
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

by:Arthur_Wood
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 7996024
Correct, a STACK is Last In First Out, while a QUEUE is First In First Out
0
 
LVL 44

Expert Comment

by:Arthur_Wood
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

by:CleanupPing
ID: 9447609
jhook53:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question