1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Liula [17]
4 years ago
8

Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algo

rithm to sort one of the arrays in ascending order. The function should keep count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other arrays. It should also keep count of the number of exchanges it makes. Display these values on the screen.
Computers and Technology
1 answer:
Anit [1.1K]4 years ago
3 0

Answer:

The C++ code is given below

Explanation:

#include<iostream>

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<size; j++)

{

if (arr[position] > 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<size;i++)

cout << arr[i] << " " ;

cout << endl;

}

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;

}

You might be interested in
What are the different options in a page layout feature ? Select three options
Sever21 [200]

Answer:

Half Center Right Left, theres four

Explanation:

5 0
3 years ago
Now plz<br>draw the main memory​
Sophie [7]

Answer: Here is my answer- I hope it helps! Btw I did search this up but I change some words so I don't get in trouble again ; - ;

Explanation: A unit of measurement is a definite importance of an amount, defined and adopted by convention or by law, that is used as a standard for measurement of the same kind of amount. Any other amount of that kind can be expressed as a multiple of the unit of measurement. For example, a length is a physical amount.

3 0
3 years ago
This is the thing that I don't understand why did they banned private chat like there are long-distance relationships, and frien
zavuch27 [327]

Answer:

lil

Explanation:

7 0
3 years ago
Read 2 more answers
What are considered to be among the earliest adhesives?
miss Akunina [59]
If you mean glue, then heres a list of what I can remember. 
1.<span>Epoxy resins
2.</span><span>.Acrylic resin.
3. polyester resin</span>
8 0
3 years ago
To stretch a photo or video to fill the project frame click on the clip in the timeline and adjust which setting in the effects
astra-53 [7]

Answer:

Explanation:

In video editing programs we can use the timeline in different ways, for example:

  • Speed/Duration command
  • Rate Stretch tool
  • Time Remapping feature

We can modify the speed of the clip making it faster or slower, or we can modify the duration, shortening or lengthening the video frame by frame, this method can be used in the audio too.

7 0
3 years ago
Other questions:
  • Which of the following is true of Shareable Content Object Reference Model (SCORM)? Group of answer choices guidelines that allo
    7·1 answer
  • If a domain consists of dcs that are running versions of windows server earlir than windows server 2008, what replication method
    12·1 answer
  • Name the different tools used byMMDB.
    14·1 answer
  • If I Uninstall Nba 2k 19 from my ps4 will my career be gone forever?​
    5·2 answers
  • Among the eight unique features of​ e-commerce, which is related to the ability to interact with web technology​ everywhere?
    14·1 answer
  • What is your favorite coler and what do you like to do and
    13·1 answer
  • Which methods will remove filters? Check all that apply.
    6·2 answers
  • Public class Dog
    7·1 answer
  • Ashley works for a company that helps hospitals hire new doctors. They have written a list of strategies that can be used to int
    12·1 answer
  • How computer viruses spread from one computer to another​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!