//CIS 610-251 //Assignment # 3 Question 6 //Due Oct 7,1999 #include class IntArray { private: int * arr; public: IntArray(int*); IntArray(); void Sort(int); void Sort2(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 from 0 to nth element void IntArray::Sort(int n) { int temp=0,i=-1; if (n>0) { while (++i<(n)) { if (arr[i] > arr[n]) { temp=arr[i]; arr[i]=arr[n]; arr[n]=temp; } }//end while Sort(n-1); }//end if } //part b. Sorts the array past nth item. void IntArray::Sort2(int n) { int temp=0,i=n+1; if (n<9) { while (++i<10) { if (arr[n+1] > arr[i]) { temp=arr[i]; arr[i]=arr[n+1]; arr[n+1]=temp; } } Sort2(n+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 << "\nUnsorted Array: " ; ia.Print(); ia.Sort(3); cout << "\nSorted from 0 to 3rd: " ; ia.Print(); ia.Sort2(4); cout << "\nSorted past 4th: " ; ia.Print(); cout << '\n'; return 0; }