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
Who invented the ENIAC? More than one answer may apply.
andriy [413]

Answer:John Mauchly and Presper Eckert

Explanation:

3 0
3 years ago
To write on a cd-rw disc, users must have cd-rw software and a cd-rw ____.
Karo-lina-s [1.5K]
Hello there!

It would be A cd - rw Drive.

Hope This Helps You!
Good Luck :)
4 0
3 years ago
What can you use on Code.org's Web Lab to find and fix problems when you are writing code for your website?
Lunna [17]

Answer:

I think I need your ip for thissssssssssssssssss

8 0
3 years ago
71 81 77 15 63 96 36 51 77 18 17
sp2606 [1]

Answer:

Following are the solution to this question:

Explanation:

This algorithm uses the divide and rule approach works, which splits the list into two sublists depending on if they are smaller or larger than the pivotal factor. It has O(n*log n) complexity.

It splits down the list in more than one version frequently till every sublist becomes based on a single element and fuses it to offer an ordered array. The merge type works according. It has O(n*log n) complexity.

Please find the attachment file of the sorting.

4 0
3 years ago
Use a spreadsheet to solve this business problem. The owners of an electronics store want to find which of their products makes
Tom [10]

Answer:

Computer Monitors earned him maximum profit. For details, please check the attachment.

Explanation:

Please check the attachment.

Download xlsx
5 0
4 years ago
Other questions:
  • is a specific system for gathering information from a single group of respondents by continuously monitoring the advertising, pr
    13·1 answer
  • For each entity, select the attribute that could be the unique identifier of each entity.
    12·1 answer
  • __________ refers to rules, statutes, codes, and regulations established to provide a legal framework within which business may
    13·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
  • What is the volume of a rectangular prism with a length of 812 centimeters, width of 913 centimeters, and a height of 1225 centi
    12·1 answer
  • What is it called when servers on the Internet supply applications as a service, rather than a product
    14·1 answer
  • What is a good range for CPU usage to be considered running well?
    15·1 answer
  • How does the dns solve the problem of translating domain names like example.com into ip addresses?
    10·1 answer
  • How to test someone elese internet speed from a distance
    15·1 answer
  • the ghost adventures team uses a variety of tools and technology in investigations. which one is described as an adjustable freq
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!