Thread: queue / stack

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    43

    queue / stack

    Hello I am unclear about queue and stacks, here are my questions:

    1) I am using the compiler CodeWarroir: and wanted to use a queue, I have used the declaration: queue <int> q and of course included the queue library, I keep getting an error that it doesn't recognize "queue", is my declaraion of the queue wrong??

    2) also...I am confused on what is the difference between a stack and a queue, I stack I understand is like when you stacksome item, and then first one pushed is the one at the bottom...and how do you declare a stack??

    thanks for the help!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Make sure you have the correct declarations.

    -----
    #include <stack>
    #include <queue>

    // instantiate a stack container of integers

    std::stack<int> myIntStack;
    myIntStack.push(1);
    ...


    // instantiate a queue container of integers

    std::quaue<int> myIntQueue;
    myIntQueue.push(1);
    -----

    stack and queue are opposite. A stack is last-in-first-out. Imagine a stack of dishes. A queue is first-in-first-out. Imagine waiting in line.

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    43
    thanks ..it worked..I had done a declaration as queue<int> q; initially in UNIX, not std::queue <int> q. I wasn wondering why my initially declaration as queue<int> q did not work with my new compiler codewarrior???

    thanks for any explanation!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  4. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  5. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM