Notes (2015-07-24)

Source: Internet
Author: User
Tags comparable

STL-related notes

The following is the basic usage of the vector queue map set stack
Can be compiled with comments to view

1#include <vector>2#include <iostream>3#include <queue>4#include <map>5#include <Set>6#include <stack>7 using namespacestd;8 9 #defineREP (n) for (int o=0;o<n;o++)Ten  One intMain () { A  -cout<<"vector function"<<Endl; -vector<int> VEC;//declare an integer vector named Vec thevector<int>::iterator It_vec;//iterators -Vec.clear ();//Clear -cout<<"Inserting Data"<<Endl; -Vec.push_back (1);//Insert at end +Vec.push_back (3); -It_vec=vec.end ();//point to the end of the VEC +it_vec--;//move forward one (both 1 and 3 in the middle) AVec.insert (It_vec,2);//Insert 2 here atREP (Vec.size ()) cout<<vec[o]<<endl;//Accessing Data -cout<<"output after first data is cleared"<<Endl; - vec.erase (Vec.begin ()); -It_vec=Vec.begin (); - REP (Vec.size ()) { -cout<<*it_vec<<endl;//Accessing Data init_vec++;//back one -     } tocout<<"#####################################"<<endl<<Endl; +  -  thecout<<"map Function"<<Endl; *map<string,vector<int> > m;//declares that the type of key is a string value of type int vector mapping m $map<string,vector<int> >::iterator it_map;//iteratorsPanax Notoginsengcout<<"Inserting Data"<<Endl; -M.insert (pair<string,vector<int> > ("AAA", VEC)); theIt_map=m.find ("AAA");//or specify the location of the key (iterator) +cout<<"Key:"<<it_map->first<<Endl; Acout<<"Value:"<<Endl; theREP (Vec.size ()) cout<<"   "<<vec[o]<<Endl; +cout<<"find a nonexistent data find () will return to the end of the map"<<Endl; -It_map=m.find ("niconiconi~"); $     if(It_map==m.end ()) cout<<"No niconiconi~"<<Endl; $cout<<"#####################################"<<endl<<Endl; -  -cout<<"Set function"<<Endl; the     Set<int> s;//declares an integer collection -     Set<int>::iterator It_set;//iteratorsWuyicout<<"flashbacks insert data and have a duplicate of 4"<<Endl; theS.insert (5); -S.insert (4); WuS.insert (4); -S.insert (2); AboutS.insert (1); $it_set=S.begin (); -      while(it_set!=S.end ()) { -cout<<*it_set<<Endl; -it_set++; A     } +cout<<"Output 4 automatically retains one, and data from small to large output"<<Endl; thecout<<"#####################################"<<endl<<Endl; -  $  the  thecout<<"Queue function"<<Endl; thequeue<string> q;//declaring a string-type queue Q thecout<<"Insert sequentially"<<Endl; -Q.push ("L"); inQ.push ("O"); theQ.push ("V"); theQ.push ("E"); AboutQ.push ("L"); theQ.push ("I"); theQ.push ("V"); theQ.push ("E"); +Q.push ("!"); -      while(!Q.empty ()) { thecout<<Q.front ();Bayi Q.pop (); the     } thecout<<Endl; -cout<<"First the team, first out ."<<Endl; -cout<<"#################################"<<endl<<Endl; the  the  the  thecout<<"priority_queue function"<<Endl; -priority_queue<string> PQ;//declares priority_queue A string-type priority Queue thecout<<"to insert data with comparable size in a random order"<<Endl; thePq.push ("B"); thePq.push ("A");94Pq.push ("C"); the      while(!Pq.empty ()) { thecout<<pq.top (); the Pq.pop ();98     } Aboutcout<<Endl; -cout<<"first come out with a big weight"<<Endl;101cout<<"###############################"<<endl<<Endl;102 103cout<<"Stack function"<<Endl;104stack<string> STA;//declaring a stack of a string type thecout<<"Insert data in reverse"<<Endl;106Sta.push ("+");107Sta.push ("+");108Sta.push ("C");109          while(!Sta.empty ()) { thecout<<sta.top ();111 Sta.pop (); the     }113cout<<Endl; thecout<<"get in first, then come out."<<Endl; the     return 0; the}

Compilation Result:

Vector function
Inserting data
1
2
3
Output after first data is cleared
2
3

#

Map function
Inserting data
Key:aaa
Value
2
3
Find a nonexistent data find () will return to the end of the map
No niconiconi~

#

Set function
Flashbacks insert data and have a duplicate of 4
1
2
4
5
Output 4 automatically retains one, and data from small to large output

#

Queue function
Insert sequentially
lovelive!
First the team, first out.

#

priority_queue function
To insert data with comparable size in a random order
Cba
First come out with a big weight

#

Stack function
Insert data in reverse
C++
Get in first, then come out.

Notes (2015-07-24)

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.