C + + Sequential container Adapter

Source: Internet
Author: User

The first time I saw a stack, I thought it was a container with the same status as a vector, not actually

Official explanation: Stacks is a type of container adaptor, specifically designed to a LIFO context (last-in-first-out), where elements ar e inserted and extracted only from one end of the container

In fact, when our phone is charging, the big guy that connects the USB port and Jack is the adapter. Essentially, an adapter is a mechanism that makes something behave as if it were something else.

Put an example of a stack application first:

1#include <iostream>2#include <stack>3 4 using namespacestd;5 6 intMain ()7 {8stack<int>IntStack;9      for(size_t i =0; I! =Ten; i++)Ten Intstack.push (i); One      while(!intstack.empty) { A         intval = Intstack.top ();//returns the top element of the stack, but does not eject -cout <<Val;  -Intstack.pop ();//pops the top of the stack element, but does not return the element value the     }    -cout <<Endl; -     return 0; -}
Seg_container_adaptor_stack

C + + Sequential container Adapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.