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
777dan777 [17]
4 years ago
11

Write a program in C++ to implement bubblesort using the swap function ?

Computers and Technology
1 answer:
marishachu [46]4 years ago
3 0

C++ program for implementation of Bubble sort  

#include <bits/stdc++.h>  

using namespace std;  

 void swap(int *x, int *y)  /*Defining Swap function of void return type*/

{  

  int temp = *x;  //Swaping the values  

   *x = *y;  

   *y = temp;  

}  

void bubbleSort(int array[], int n) /*Defining function to implement bubbleSort  */

{  

  int i, j;  

  for (i = 0; i < n-1; i++)      

      for (j = 0; j < n-i-1; j++)  /*The last i components are already in location  */

      if (array[j] > array[j+1])  

          swap(&array[j], &array[j+1]);  //Calling swap function

}  

int main()  //driver function

{  

   int array[] = {3, 16, 7, 2, 56, 67, 8}; //Input array  

   int n = sizeof(array)/sizeof(array[0]);  //Finding size of array

   bubbleSort(array, n); //Function calling  

   cout<<"Sorted array: \n";  

   for (int i = 0; i < n; i++)  //printing the sorted array

       cout << array[i] << " ";  

   cout << endl;  

 return 0;  

}  

<u>Output</u>

Sorted array:  

2 3 7 8 16 56 67

You might be interested in
What is the utility of a lever?
Kamila [148]
Muy cosas.
 fazer una montanha russa andar,ativar una armadilha, ativar una puerta etc.
3 0
3 years ago
Read 2 more answers
A technician wants to connect a computer to a high-definition television (HDTV). The technician has attached an HDMI cable from
kirill115 [55]

The correct option that was used for audio pass-through is;

<u><em>Option B; HDMI Out</em></u>

<u><em /></u>

      We are told that the technician attached an HDMI cable from the video card to connect it to the television.

Now, HDMI means High Definition Multimedia Interface and it has two parts which are HDMI In and HDMI Out.

HDMI Out is used to feed the audio pass through and visual signals,

whereas HDMI In is used to receive these audio pass through and visual

signals.

Looking at the given options, the only correct answer is HDMI Out.

Read more at; brainly.com/question/24637033

4 0
3 years ago
You have been asked to write a program that will ask the user for his or her pizza order and display it. The order will include
Dvinal [7]

Q asks to write

1. input statement that prompts the user for the type of cheese:

What kind of cheese you like?

Input TYPE OF CHEESE

2. Print statement that clearly displays the output message related to the type of cheese:

Print "Pizza has" TYPE OF CHEESE "type of cheese."


5 0
3 years ago
Plz help me I need this doneee
Vladimir79 [104]
Answer: I think it’s true
5 0
3 years ago
A farmer in Iowa owns 450 acres of land. He is going to plant each acre with wheat or corn. Each acre planted with wheat yields
valkas [14]

Answer:

Explanation:

the constrained variables are acres of wheat(let a) (cell I6) and acres of corn(let b) (cell J6)

Both the above constraints are positive and integer also

The land constraint of 400 i.e (I6+J6)<= 450 ="" is given="" by="" constraint=""><=l7 where k8="">

The fertilizer constraint of 1200 tons is given by K8<=l8 , where="" k8="">

The worker constraint of 1000 is given by K9<=l9 where k9="">

The variable to be maximized K5 is given by constraint K5=SUMPRODUCT(I5:J5,I6:J6)

b) Let a be the acres of wheat and b be the acres of corn.

so the constraints are

(a+b) <>

2a+4b<>

3a+2b <=1000 ="" ="" where="" a="">=0 and b>=0 and both a and b are integers

a is plotted on horizontal line and b is on vertical line

for 200 ton fertilizer the maximum profit occurs when 200 acres each are cultivated under wheat and corn.

7 0
4 years ago
Other questions:
  • Mitchell is assisting her teacher in a project by entering data into the spreadsheet. Which types of data can Michelle enter in
    14·2 answers
  • What effects will the different types of lighting produce on mountains?
    15·1 answer
  • Given a UNIX file system with 1024-byte blocks, how many disk accesses are needed to access bytes 2500-2503 of a file (assume th
    12·1 answer
  • Students who finish their homework after school are meeting a. intrapersonal and short-term goals b. normative and short-term go
    13·2 answers
  • HEPME <br> ZOOM<br> IN <br> STOP<br> GIVIJG<br> ME <br> LINKS <br> !!
    9·1 answer
  • Use the drop-down menus to complete the sentences about the Calendar view Arrange command group.
    6·1 answer
  • 5.5 Learning Objective: To demonstrate that the student understands the definition of Big O. To demonstrate that the student und
    11·1 answer
  • Which of these statements are true about domain controllers (dcs)? check all that apply.
    5·2 answers
  • Which statements are TRUE about web services protocols? (Select TWO responses) SOAP and REST are both web service communication
    15·1 answer
  • Password ____ traverse the network searching for passwords from remote authentication systems.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!