CHAPTER11-1.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER11-1.cpp
- #include <algorithm>
- #include <iostream>
- using namespace std;
- void main()
- {
- const int ARRAY_SIZE = 8 ;
- int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
- int *location ; // stores the position for the first pair of matching consecutive elements.
- int i ;
- // print content of IntArray
- cout << "IntArray { " ;
- for(i = 0; i < ARRAY_SIZE; i++)
- cout << IntArray[i] << ", " ;
- cout << " }" << endl ;
- location = adjacent_find(IntArray, IntArray + ARRAY_SIZE) ;
- //print the matching consecutive elements if any were found
- if (location != IntArray + ARRAY_SIZE) // matching consecutive elements found
- cout << "Found adjacent pair of matching elements: (" << *location << "," << *(location + 1) << "), " <<"at location " << location - IntArray << endl;
- else // no matching consecutive elements were found
- cout << "No adjacent pair of matching elements were found"<< endl ;
- }