Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago