Question: Create a flow chart for the follwing C++ code #include using namespace std; void swap(int &a,int &b) { int temp = a; a = b;

Create a flow chart for the follwing C++ code

#include using namespace std;

void swap(int &a,int &b) { int temp = a; a = b; b = temp; }

int bubbleSort(int *arr,int size) { int count = 0; for (int i = 0; i < size-1; i++) { for (int j = 0; j < size-i-1; j++) { if (arr[j] > arr[j+1]) { swap(arr[j],arr[j+1]); count++; } } } return count; }

int selectionSort(int *arr,int size) { int position,count = 0; for (int i = 0; i < size-1; i++) { position = i; for (int j = i+1; j arr[j]) position = j; } if (position != i) { swap(arr[i],arr[position]); count++; } } return count; }

void printArray(int *arr,int size) { for(int i=0;i

int main() { int arr[20] = {1,3,4,2,6,7,8,5,12,13,14,15,9,10,11,20,19,18,17,16}; int arr1[20] = {1,3,4,2,6,7,8,5,12,13,14,15,9,10,11,20,19,18,17,16}; cout << "Array Before sorting : "; printArray(arr,20); int count = bubbleSort(arr,20); cout << "Array After sorting : "; printArray(arr,20); cout << "Array Before sorting : "; printArray(arr1,20); int count1 = selectionSort(arr1,20); cout << "Array After sorting : "; printArray(arr1,20); cout << "Number of exchanges in bubble sort is : " << count << endl; cout << "Number of exchanges in selection sort is : " << count1 << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!