1 // dynamic array 2 vector <int> thevector; 3 thevector. push_back (1); 4 thevector. push_back (2); 5 thevector. push_back (3); 6 thevector. pop_back (); 7 vector <int>: iterator itvector; 8 cout <"vector" <Endl; 9 for (itvector = thevector. begin (); itvector! = Thevector. end (); itvector ++) 10 {11 cout <* itvector <Endl; 12} 13 14 // two-way linked list 15 list <int> theList; 16 theList. push_back (1); 17 theList. push_front (2); 18 list <int>: iterator itlist; 19 cout <"list" <Endl; 20 for (itlist = theList. begin (); itlist! = TheList. end (); itlist ++) 21 {22 cout <* itlist <Endl; 23} 24 25 // stack 26 stack <int> thestack; 27 thestack. push (1); 28 thestack. push (2); 29 thestack. push (3); 30 thestack. pop (); 31 cout <"stack" <Endl; 32 While (! Thestack. empty () 33 {34 cout <thestack. top () <Endl; 35 thestack. pop (); 36} 37 38 // queue 39 queue <int> thequeue; 40 thequeue. push (1); 41 thequeue. push (2); 42 thequeue. push (3); 43 thequeue. pop (); 44 cout <"queue" <Endl; 45 while (! Thequeue. empty () 46 {47 cout <thequeue. front () <Endl; 48 thequeue. pop (); 49} 50 51 // red/black tree 52 Map <int, String, less <int> themap; // Add space 53 themap at the last position of the template. insert (Map <int, String, less <int> >:: value_type (0, "zero"); 54 themap. insert (Map <int, String, less <int> >:: value_type (1, "one"); 55 themap. insert (Map <int, String, less <int >:: value_type (2, "two"); 56 Map <int, String, less <int> :: iterator itmap; 57 cout <"Map" <Endl; 58 for (itmap = themap. Begin (); itmap! = Themap. End (); itmap ++) 59 {60 cout <(* itmap). Second <Endl; 61}
Common STL containers