CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: STL stack queue

  1. #1
    Join Date
    Feb 2014
    Posts
    11

    STL stack queue

    #include <iostream>
    #include <vector>
    #include <stack>
    Hi!
    In the Standart Template Library I am stading stack and queues.

    One way to instantiate is creating a stack that uses an underlying container , in this case vector,

    Can anyone give me an example about how to use this?
    I mean how can I use the function members of the container vector in the next code?
    What is the difference between a simply stack of integers and the stack of integers containes in a vector?

    Thanks


    using namespace std;

    int main()
    {

    stack<int,vector<int>> mystack; //vector ???????

    mystack.push(2);
    mystack.push(8);

    cout<<mystack.top();

    return 0;
    }

  2. #2
    Join Date
    Jul 2013
    Posts
    576

    Re: STL stack queue

    Quote Originally Posted by Jose M View Post
    how can I use the function members of the container vector in the next code?
    The second parameter of a stack definition allows you to define which container the stack is supposed to use internally. The default is a deque and you can change it to for example a vector as you suggest.

    But this doesn't influence the stack interface, it will remain the same. A stack is a stack. But the properties of the stack will reflect that of the internal container. For example a deque and a vector handles memory differently when they grow/shrink and the stack will adopt the respective behaviour.

    I recommend The C++ Standard Library, second edition, by Josuttis as a very good reference for topics like this.

  3. #3
    Join Date
    Feb 2014
    Posts
    11

    Re: STL stack queue

    ok thanks... I undertand now

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured