#include #include #include using namespace std; template //For Template void bogosort(std::vector& array) //For bogosort { while (! is_sorted(array)) { std::random_shuffle(array.begin(), array.end()); } } template bool is_sorted(const std::vector& array) //Conforming for display { for (typename std::vector::size_type i = 1; i < array.size(); ++i) { if (array[i] < array[i-1]) { return false; } } return true; } std::vector a (10); //Creates a vector of size 10 int arr[10]; template void accept(std::vector& array) //Accepts data to a vector { int c; for(c = 0; c < 10; c++) cin>>arr[c]; a.assign (arr,arr+10); //Assign array data to the vector } template void display(std::vector& array) //Display the vector contents { for (std::vector::iterator it = array.begin(); it != array.end(); ++it) std::cout << \' \' << *it; } template void selection(std::vector& arr) //Selection soring operation { int mini, loc, temp, x, y; mini = arr[0]; for(x = 0; x <= arr.size()-1; x++) { mini = arr[x]; //x position value of array is considered as minimum value loc = x; //Stores the location of the minimum value for(y = x + 1; y <= arr.size()-1; y++) { if(arr[y] < mini) //Checks the already minimum value with the array contents { mini = arr[y]; //Stores the new minimum value loc = y; //Stores the location of the minimum value } } if(loc != x) //If it is not the same location { temp = arr[x]; arr[x] = arr[loc]; arr[loc] = temp; } } } template void bubble(std::vector &ar) //Bubble sort operation { bool swapp = true; while(swapp) { swapp = false; for (int i = 0; i < ar.size()-1; i++) { if (ar[i]>ar[i+1] ) { ar[i] += ar[i+1]; ar[i+1] = ar[i] - ar[i+1]; ar[i] -=ar[i+1]; swapp = true; } } } } int main() { char ch; do { cout<<\"\ MENU\"; cout<<\"\ a Fill the array with user input\"; cout<<\"\ b Display the array\"; cout<<\"\ c Suffel the array element randomly\"; cout<<\"\ d Sort the array using bubble sort\"; cout<<\"\ e Sort the array using Selection Sort\"; cout<<\"\ f Exit Program\"; cout<<\"\ Enter your choice: \"; cin>>ch; switch(ch) { case \'a\': case \'A\': accept(a); cout<<\"\ Accept data operation completed \ \"; break; case \'b\': case \'B\': display(a); cout<<\"\ Display data operation completed \ \"; break; case \'c\': case \'C\': bogosort(a); bool b = is_sorted(a); if(b == true) display(a); cout<<\"\ Bugg Sorting operation completed \ \"; break; case \'d\': case \'D\': bubble(a); display(a); cout<<\"\ Bubble Sort operation completed \ \"; break; case \'e\': case \'E\': selection(a); display(a); cout<<\"\ Selection Sort operation completed \ \"; break; case \'f\': case \'F\': exit(0); default: cout<<\"\ Wrong Choice\"; } }while(1); //Loop will continue infinitely till F or f is pressed } Output MENU a Fill the array with user input b Display the array c Suffel the array element randomly d Sort the array using bubble sort e Sort the array using Selection Sort f Exit Program Enter your choice: a 10 5 4 78 9 65 3 1 45 66 Accept data operation completed MENU a Fill th.