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
Troyanec [42]
3 years ago
10

Given an array of values which initially contains 9 8 7 6 5 4 3 2 1, what does the array look like after bubble sort has execute

d 3 passes, which means that the largest 3 values have been moved to their correct positions in the array.
Computers and Technology
1 answer:
Phantasy [73]3 years ago
7 0

Answer:

//Here is code in C++.

//include header

#include <bits/stdc++.h>

using namespace std;

// function to print the array

void out_arr(int inp[], int len)

{

for (int i = 0; i < len; i++)

 cout << inp[i] << " ";

cout << endl;

}

// main function

int main()

{

   // decalare and initialize the array

int inp[] = {9,8,7,6,5,4,3,2,1};

//find the length of array

int len = sizeof(inp)/sizeof(inp[0]);

int x, y;

// perform bubble sort, only 3 pass

for (x = 0; x < 3; x++)  

{

for (y= 0; y< len-x-1; y++)

 if (inp[y] > inp[y+1])

 {

  int t=inp[y];

  inp[y]=inp[y+1];

  inp[y+1]=t;

 }

 

 cout<<"array after "<<x+1<<" pass"<<endl;

 // print the array after every pass

     out_arr(inp, len);

}

return 0;

}

Explanation:

Declare an integer array "inp" and initialize with {9,8,7,6,5,4,3,2,1}. Find the length of the array.In first pass of bubble sort, largest value is placed at the correct position in the array. And in the second, second largest value is placed at its correct position. After the n pass, array will be sorted. In each pass, each element is compared with the next element. if the value is greater than swap them. This continues for all elements in each pass. In the end of a pass a value is placed correctly. So if there is only 3 pass then 3 largest values will be placed at their right place.

Output:

8 7 6 5 4 3 2 1 9                                                                                                              

array after 2 pass                                                                                                            

7 6 5 4 3 2 1 8 9                                                                                                              

array after 3 pass                                                                                                            

6 5 4 3 2 1 7 8 9

You might be interested in
What benefit does internet have​
Licemer1 [7]
Information can be transferred and passed way easier.
5 0
3 years ago
Why would an online survey of 2,000 visitors to your college’s Web site be of little use in assessing the neighboring community’
musickatia [10]

Answer: the sample is not representative of the community.

Explanation:

Online surveys or surveys in general are made to obtain relevant information about a particular issue. If samples are not representative of that issue, they end up having little use.  

4 0
4 years ago
Which of the following is a domestic business activity?
harkovskaia [24]
What are the options?

7 0
3 years ago
Read 2 more answers
No spamming or links
Hitman42 [59]
I think the answer is true,
8 0
3 years ago
Read 2 more answers
The tcp protocol provides error detection and correction. <br><br> a. True <br> b. False
ANEK [815]
B. False

Explanation

TCP provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network.
4 0
2 years ago
Other questions:
  • I just started game development using unity, I’m trying to control my sphere moving on a flat surface using the W,A,S,D keys, if
    5·1 answer
  • When you are working on an unsaved document on a PC, where is the document temporarily saved?
    5·1 answer
  • in java how do i Write a program that reads a set of integers, and then prints the sum of the even and odd integers.
    6·1 answer
  • You are requesting information about wireless connectivity for your workplace computers. Because you expect the information to b
    15·1 answer
  • Given a matrix input_matrix, return a Numpy array that consists of every entry of A that has: an even row index in the range [0,
    9·1 answer
  • Refer to the method f: Public int f( int k, int n ) { if( n == k ) return k; else if( n &gt; k ) return f( k, n - k ); else retu
    8·1 answer
  • In order to preview an attachment in an e-mail, click the attachment in the ______
    8·1 answer
  • ____ is a technique for confirming that q received packet or frame is likely to match what was sent
    15·1 answer
  • In two to three sentences, define "home row" and explain why it is important.
    6·2 answers
  • How to do or create a shepard tone using additive synthesis in Pure Data. Please help, desperate!!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!