C++ÃæÊÔÌâÖ®ÈÝÆ÷ ÏÂÔØ±¾ÎÄ

±ê׼ģ°å¿â

£½£½Í·Îļþ£½£½ #ifndef PRINT_H #define PRINT_H 1

//Êä³öÒ»¸öÖ¸¶¨Çø¼äÖеÄËùÓÐÊý¾Ý£¨º¬Í·²»º¬Î²£© #include using namespace std; template void print(T b,T e,char c=' ') {

while(b!=e) cout<<*b++<

#endif

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- /*

±ê×¼ÈÝÆ÷£¨ÀàÄ£°å£©¹²ÐÔ£º

¹¹Ô캯Êý£ºÎ޲ι¹Ô죬¿½±´¹¹Ôì£¬Çø¼ä¹¹Ô죨Á½¸öµü´úÆ÷±íʾµÄÁ½¸öλÖã© Îö¹¹£º

µü´úÆ÷Ïà¹Ø£ºÕýÏò .begin(), .end(), ·´Ïò .rbegin(), .rend() iterator,reverse_iterator,const_iterator,const_reverse_irerator * -> = ++ == != --

²åÈ룺isert(pos,element),ÆäÖÐpos±íʾ²åÈëΪλÖã¬ÊÇÒ»¸öµü´úÆ÷ ɾ³ý£º.erase(pos), erase(pos_beg,pos_end) Çå³ý£º.clear()

´óС£º.size(), .max_size(), .empty() ½»»»£º.swap(c2), swap(c1,c2) ÔËËã·û£º= > < >= <= == != */

#include #include #include using namespace std; #include \int main() {

int a[5]={33,11,55,22,44};

vector vi(a,a+5);//´´½¨Ò»¸öÊý¾Ý¿Õ¼ä cout<

vector::iterator b=vi.begin(); while(b!=vi.end()) cout<<*b++<<' '; cout<

for(int i=0;i<5;i++) cout<

print(vi.begin(),vi.end());

print(a,a+5); print(vi.rbegin(),vi.rend()); b=vi.begin();

vi.insert(++++b,66);//ÔÚÖ¸¶¨Î»ÖòåÈëÊý¾Ý vi.insert(vi.begin(),77); vi.insert(vi.end(),88); print(vi.begin(),vi.end());

cout<

vi.erase(++++vi.begin(),--vi.end());//ɾ³ýÇø¼ä print(vi.begin(),vi.end());

vector v2(a,a+5); print(v2.begin(),v2.end()); vi.swap(v2);

cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); swap(vi,v2);

cout<<\

print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vector t=vi; vi=v2; v2=t;

cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vi.clear();

cout< x;

cout<<\µ±Ç°ÈÝÁ¿£º\} /* 5

11 22 33 44 55 33 11 55 22 44 11 22 33 44 55 33 11 55 22 44 55 44 33 22 11

77 11 22 66 33 44 55 88 8/1073741823

77 11 22 66 33 55 88 77 11 88

33 11 55 22 44

--------------------------- 33 11 55 22 44 77 11 88

--------------------------- 77 11 88

33 11 55 22 44

========================= 33 11 55 22 44 77 11 88 0

vectorµ±Ç°ÈÝÁ¿£º0 */

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-vectorÈÝÆ÷¹²ÐÔ #include #include #include using namespace std; #include \int main() {

int a[5]={33,11,55,22,44};

vector vi(a,a+5);//´´½¨Ò»¸öÊý¾Ý¿Õ¼ä cout<

vector::iterator b=vi.begin(); while(b!=vi.end()) cout<<*b++<<' '; cout<

for(int i=0;i<5;i++) cout<

print(vi.begin(),vi.end()); print(a,a+5);

print(vi.rbegin(),vi.rend()); b=vi.begin();

vi.insert(++++b,66);//ÔÚÖ¸¶¨Î»ÖòåÈëÊý¾Ý vi.insert(vi.begin(),77); vi.insert(vi.end(),88); print(vi.begin(),vi.end());

cout<

vi.erase(++++vi.begin(),--vi.end());//ɾ³ýÇø¼ä print(vi.begin(),vi.end()); vector v2(a,a+5); print(v2.begin(),v2.end()); vi.swap(v2);

cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); swap(vi,v2);

cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vector t=vi; vi=v2;