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]
3 years ago
11

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

Computers and Technology
1 answer:
marishachu [46]3 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
one day when rahul went to his computer lab and saw that all the computers were connected to a single printer and whoever is giv
amm1812

Explanation:

you can connect multiple PCs to the wireless printer and print your documents from each one of them as long as the printer can be connected to the same network . You need the disc that came with the wireless printer to install the correct drivers on your computers and laptops.

hope it helps ( brainleist please )

7 0
3 years ago
How do I use files and functions in programming?
maw [93]

answer:

1.The program comes to a line of code containing a "function call".

2.The program enters the function (starts at the first line in the function code).

3.All instructions inside of the function are executed from top to bottom.

4.The program leaves the function and goes back to where it started from.

5.Any data computed and RETURNED by the function is used in place of the function in the original line of code.

3 0
3 years ago
What obstacles could prevent you from getting and keeping a job
stepladder [879]
Drugs, No Collage, Gangs, bad grades, Criminal Records →
7 0
4 years ago
20 examples of input device?
kiruha [24]

Answer:

Computer keyboard,Microphone,Image scanner,Touchscreen,light pen

Explanation:

sorry  that   all  device i  know

8 0
3 years ago
Read 2 more answers
The java compiler is able to find all programmer errors.
Troyanec [42]
No compiler can do that. Maybe with AI, but that's beyond the scope of a compiler.
5 0
4 years ago
Other questions:
  • If you find yourself boxed in by a vehicle on your left or right _____________
    14·2 answers
  • Python
    14·1 answer
  • Which logic gate produces an output of 1 only if both it’s inputs are 0?
    5·1 answer
  • Incident damage ____ is the rapid determination of the scope of the breach of the confidentiality, integrity, and availability o
    6·1 answer
  • 2. An evil twin attack that broadcasts a legitimate SSID for an unauthorized network is an example of what category of threat? A
    9·1 answer
  • A junior administrator is having issues connecting to a router's console port using a TIA/EIA 568B standard cable and a USB seri
    5·1 answer
  • What do you need for digital photography? 1. 2. 3.
    13·1 answer
  • ...This is totally a question
    6·1 answer
  • Select the examples that best demonstrate likely tasks for Revenue and Taxation workers. Check all that apply. Brenda works for
    11·2 answers
  • What are the five generations of computer software​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!