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
Which of the following is a real job title on The interactive media career pathway?
Serhud [2]

Answer:

The right answer is A

Explanation:

Plzzzzzzzzzzzzz give me brainiest

4 0
2 years ago
Read 2 more answers
What language used orthogonality as a primary design criterion?
pogonyaev
LIPS a functional language is one in which computations are made primarily by applying function to given program
4 0
3 years ago
You are most likely to use<br> images for photos or digital paintings.
Lubov Fominskaja [6]

Answer: Digital Paintings

7 0
3 years ago
How many fixes are available for Adobe Photoshop CS4 (64 Bit)?
arsen [322]

Answer:

There are three (3) fixes in adobe cs4.

Explanation:

Adobe photoshop cs4 is a version of the creative cloud's professional graphic applications used to edit pictures, design interfaces, make graphical illustrations, draw and animate the drawings, etc.

It can be installed in several computer operating system platforms like linux, mac and windows. The adobe photoshop cs4 doesn't support the windows installation and might run into several issues. There are other issues in other supported platforms, but unlike for windows, there are three fixes for these problems.

4 0
3 years ago
What is a good rule of thumb for how much white space you should have in a flyer or poster
almond37 [142]
Poster because if you have that much space....well what I do is calculate it by the centimeters in square divide:)
6 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following option is correct about HCatalog?
    14·1 answer
  • What are the two most important network-layer functions in a datagram network? what are the three most important network-layer f
    7·1 answer
  • Identify the correct software or hardware applications in the passage below
    10·1 answer
  • How long does it take a letter to arrive?
    9·1 answer
  • Who's YouTube creator?
    10·2 answers
  • Wearables, video playback and tracking devices can help athletes because
    15·1 answer
  • which of the following indicates that the loop should stop when the value in the quantity variable is less than the number 50​
    13·1 answer
  • Write a program code which asks for 80 numbers between 100 and 1000 to be entered.
    7·1 answer
  • What applications would you pin to your taskbar, why?
    15·1 answer
  • A Product Manager has been given responsibility for overseeing the development of a new software application that will be deploy
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!