// File: vector2.cpp // // Simple use of STL vector container class // #include #include #include using namespace std ; const unsigned long int seed = 38913154 ; //const int reps = 10000 ; // ten thousand const int reps = 20000 ; // twenty thousand //const int reps = 200000 ; // two *hundred* thousand //const int reps = 400000 ; // four *hundred* thousand int main() { vector V ; vector::iterator it ; int x, found = 0 ; V.reserve(reps); srandom(seed) ; for (int i = 0 ; i < reps ; i++) { V.push_back(random()) ; } for (int i = 0 ; i < reps ; i++) { x = random() ; for(it = V.begin() ; it != V.end() ; it++) { if (x == *it) { found++ ; break ; } } } cout << "Number of random numbers found: " << found << "\n" ; }