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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started