Our Blog

Stack with Comment

STACK CARDS


    
int main ()
{
        stack <string> cards; /* Simple enough to create a stack */

        cards.push("King of Hearts"); /* push() will add a value */

        cards.push("King of Clubs");  /* adding some cards to the deck */

        cards.push("King of Diamonds");

        cards.push("King of Spades");

        cout << "There are " << cards.size () << " cards in the deck" << endl;

        cout << "The card on the top of the deck is " << cards.top() << endl;

        /* Will output King of Spades, since this was the last one to be added (LIFO(Last In First Out)*/

        cards.pop();//cards in the last will be poped/removed

        cout << "The top card is now " << cards.top() << endl;//The last top card is King Of Diamonds

        cout << cards.size();//to display the order of the last cards
       
        cin.get ();
       
        getch();

    }

No comments:

Post a Comment

All about Math Designed by Templateism | MyBloggerLab Copyright © 2014

Theme images by richcano. Powered by Blogger.