//tstVect.cpp -- @CopyLeft by tsaiwn@csie.nctu.edu.tw
//test STL <vector>  , and as well as my "vector"
#include "vector"
//use my "vector" if there is one in current directory; else use STL
#include<iostream>
#include<algorithm>
using namespace std;
template<class T> void print(vector<T> &x) {
   typename vector<T>::iterator it;
   for(int i=0; i < x.size( ); ++i) cout << " "<< x[i]; cout << endl;
   cout<< "size, capa= "<<x.size( )<<", "<<x.capacity( )<<"; ";
   if(x.size()==0) { cout <<" NOTHING"<<endl; return; }
   cout<< "head, tail="<< *x.begin( )<<", "<< *(x.end()-1)<<"; ";
   cout<< "front, back="<< x.front( )<<", "<< x.back( )<<endl;
}// print
int main( ) {    int bb[ ] = {12, 28, 3, 4, 58, 6, 37 };
    vector<int> x(bb, bb+5);  // only first 5 elements
    vector<double> y;
    cout << "x: "; print(x);   cout << "y: "; print(y);
    //cout<< "y.front, back="<< y.front( )<<", "<< y.back( )<<endl;
    cout << "===now do add 999 to x; add three nums to y\n";
    x.push_back(999);
    y.push_back(3.8); y.push_back(8.5); y.push_back(4.9);
    cout << "x[2] = " << x[2] << endl;   // x.front( )=555; //test
    x[2] = 333;  cout << "x[2] = " << x[2] << endl;
    cout << "x: "; print(x);   cout << "y: "; print(y);
    cout << " now do sort(x.begin( ), x.end( )); " << endl;
    sort(x.begin( ), x.end( ));   // use sort( ) in <algorithm>
    cout << "x: "; print(x);
    cout << "x[92]===" << x[92]<< "; do x.at(2)=222 ::: ";
    x.at(2) = 222; cout << x.at(2) <<" ::: "<<x[2]<< endl;
    x.at(92) = 222; cout << x.at(92) << endl;   // cause Exception
    return 0;
} /********              see   http://www.cplusplus.com
//////// 以下 先用到 自己寫 的 "vector"
C:\testc\STL>g++ tstVector.cpp
C:\testc\STL>a
x:  X  12 X  28 X  3 X  4 X  58
size, capa= 5, 5; head, tail=12, 58; front, back=12, 58
y:
size, capa= 0, 10;  NOTHING
===now do add 999 to x; add three nums to y
 X x[2] = 3
 X  X x[2] = 333
x:  X  12 X  28 X  333 X  4 X  58 X  999
size, capa= 6, 10; head, tail=12, 999; front, back=12, 999
y:  X  3.8 X  8.5 X  4.9
size, capa= 3, 10; head, tail=3.8, 4.9; front, back=3.8, 4.9
 now do sort(x.begin( ), x.end( ));
x:  X  4 X  12 X  28 X  58 X  333 X  999
size, capa= 6, 10; head, tail=4, 999; front, back=4, 999
 X x[92]===1818838560; do x.at(2)=222 :::  A  A 222 ::: 222
 A
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
//======== /// 以下是用到 C++ STL 的 <vector>   ////////////////
C:\testc\STL>ren vector vectorME
C:\testc\STL>g++ tstVector.cpp
C:\testc\STL>a
x:  12 28 3 4 58
size, capa= 5, 5; head, tail=12, 58; front, back=12, 58
y:
size, capa= 0, 0;  NOTHING
===now do add 999 to x; add three nums to y
x[2] = 3
x[2] = 333
x:  12 28 333 4 58 999
size, capa= 6, 10; head, tail=12, 999; front, back=12, 999
y:  3.8 8.5 4.9
size, capa= 3, 4; head, tail=3.8, 4.9; front, back=3.8, 4.9
 now do sort(x.begin( ), x.end( ));
x:  4 12 28 58 333 999
size, capa= 6, 10; head, tail=4, 999; front, back=4, 999
x[92]===1750359155; do x.at(2)=222 ::: 222 ::: 222

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
*********************/
