# include # include using namespace std; int main () { int arr[]= {6,2,8,4,1,3,18,26}; int *ptrarr[8]; int *temp; int i = 0; int j=0; int smallest; int smallestindex; cout <<" Original: "; // Loop Below is to print the original array for (i = 0; i < 8 ; i++) cout << arr[i]<<" "; cout << endl; // Set the array of pointers to point to corresponding elements of the int array i = 0; for (i = 0;i<8;i++) { ptrarr[i] = &arr[i]; } // nested loop to sort the pointer array by using the values of the int array i = 0; //outside loop for (int j=0;j<7;j++) { //set smallestindex to the current top of the array that still has to be sorted smallestindex = j; for (i = j+1;i<8;i++) //find the smallest value and save the smallestindex if (*ptrarr[i] < *ptrarr[smallestindex]) { smallestindex = i; } //swap the current top with the smallest index in the pointer array temp = ptrarr[smallestindex]; ptrarr[smallestindex] = ptrarr[j]; ptrarr[j] = temp; } i = 0; cout << endl; cout <<" Sorted array: "; // below loop is to print pointer array for (i = 0; i < 8 ; i++) cout << *ptrarr[i]<<" "; cout << endl; return 0; }