Web Analytics Made Easy -
StatCounter URGENT: For tommorow!! A question on queues and stacks - CodingForum

Announcement

Collapse
No announcement yet.

URGENT: For tommorow!! A question on queues and stacks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • URGENT: For tommorow!! A question on queues and stacks

    I have two main questions that i'm just not sure on how to start :


    Using C++:

    1) a) How would you implement a queue using arrays.

    b) How would you implement a stack using arrays.

    2) a) How would you implement a queue using linked lists.

    b) How would you implement a stack using linked lists.

    Any help would be greatly appreciated...
    Last edited by Smeagle; Aug 4, 2005, 01:44 AM. Reason: No language specification

  • #2
    sounds like homework to me

    Interesting note: when using google, i found one site answering all your questions. If you dont want to do your homework yourself, use google.
    I am the luckiest man in the world

    Comment


    • #3
      I'll give you some clues:
      1.a) You need to have two "pointers" (pointers not in the regular address-in-memory sense, just an int representing the index in the array) to the indexes to the head and tail of the queue, and implement wraparound functionality for them.
      1.b) You only need one "pointer" to the top of the stack.
      2.a) A simple list and references to the head and tail nodes will do.
      2.b) You'll need a two-way list (next and prev pointers) and a reference to the head of the list.

      shmoove

      Comment


      • #4
        Is this stuff not covered in your C book? I have about 10 C++ class books here and all that is covered in all of them... lol
        Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

        Comment


        • #5
          Those exact four questions were actually on a test in a class that focused around data structures.

          Comment


          • #6
            Thank you so much for the help

            Comment


            • #7
              well, what i have found, the best way to start solving a problem is just take a paper and pencil and sit away from ur computer. try to write a piece of code that u think can solve the problem, then perform a dry run, with in half an hour u will figure out at least something near a solution... !

              Comment


              • #8
                Really, it's just a little thought game.

                First, really consider what a stack and a queue really are. And you'll see that these two methods are completely logical ways of implementing them. Draw yourself some diagrams and keep asking yourself what you are keeping track of in order to simulate.

                Comment

                Working...
                X