CHAPTER4-7.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER4-7.cpp
- #include <stdlib.h>
- #include <iostream.h>
- inline int cmp (const void *a, const void *b)
- { int aa = *(int *)a;
- int bb = *(int *)b;
- return (aa < bb) ? -1 : (aa > bb) ? 1 : 0;
- }
- void main (int argc, char *argv[])
- {
- const int size = 10; // array of 10 integers
- int array [size];
- int n = 0;
- cout<<"Please input 10 integers:"<<endl;
- // read an integer into the n+1 th element of array
- while (n<size)
- {
- int temp_char;
- cin>>temp_char;
- bool find=false;
- int j=0;
- while((j<n)&&(!find))
- { find=(temp_char==array[j]); j++; }
- if(!find)
- { array[n]=temp_char; n++; }
- }
- n--; // it got incremented once too many times
- qsort (array, n, sizeof(int), cmp);
- cout<<"output the 10 sorted integers:"<<endl;
- for (int i = 0; i <= n; i++) cout << array[i] << " ";
- }