//CIS 610-251 Recursion. //Assignment # 3 Question 7 //Due Oct 7,1999 #include class IntArray { private: int * arr; public: IntArray(int*); IntArray(); int SortNFind(int,int,int); void Print(void); }; IntArray::IntArray() { arr= new int[10]; } IntArray::IntArray(int * i) { int j=-1; arr= new int[10]; while(j++<10) arr[j]=i[j]; } //Sort and Find kth smallest number if selected ith in array. int IntArray::SortNFind(int k,int n,int ith) { int temp=0, i;bool isith=false; //ensure if ith item is in the list e.g. if 2 is present in list for(i=0;i<10;i++) { if (arr[i]==ith) isith=true;} if (isith) { if (n<10) { for(i=n;i<10;i++) { if (arr[i] < arr[n]) { temp=arr[i]; arr[i]=arr[n]; arr[n]=temp; } }//end while SortNFind(k,n+1,ith); }//end if return arr[k-1]; } //if ith item not present in arr return -1 else return -1; } //Print the array void IntArray::Print(void) { int i=0; for(;i<10;i++) cout << ' ' << arr[i]; } //Main loop starts here. main() { int a[]={99,10,0,5,8,9,1,3,6,0}; IntArray ia(a); cout << "\nInput Array: " ; ia.Print(); cout << "\n4th Smallest is: " << ia.SortNFind(4,0,0); cout << '\n'; return 0; }