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
a rule that states each foreign key value must match a primary key value in the other relation is called the
makvit [3.9K]

Answer:

Referencial Integrity Contraint

Explanation:

The referential integrity constraint states that the customer ID i.e (CustID) in the Order table must match a valid CustID in the Customer table. Most relational databases have declarative referential integrity. That is to say, when the tables are created the referential integrity constraints are set up so as to maintain the quality of information.

3 0
3 years ago
What is the missing line of code? &gt;&gt;&gt; &gt;&gt;&gt; math.sqrt(16) 4.0 &gt;&gt;&gt; math.ceil(5.20) 6
Blababa [14]

Answer:

A math.pow reference

Explanation:

3 0
3 years ago
Read 2 more answers
A tornado destroyed many
m_a_m_a [10]

Answer:

D is your answer because I'm an expert

5 0
3 years ago
Read 2 more answers
What is the median of 6, 16, 9, 20, 45, 30, and 32?<br> A. 9<br> B. 16<br> C. 20<br> D. 22
Oksana_A [137]
I believe the answer to your question is going to be C. 20
Hope this helps:)
8 0
3 years ago
Which is the correct expansion of the term Internet?
dem82 [27]

Answer:

international network is the answer

6 0
3 years ago
Read 2 more answers
Other questions:
  • The U.S. economy is a free enterprise system.<br><br> True<br> False<br><br> PLEASE DONT GUESS
    8·2 answers
  • Which of the following is the best definition of being a “digital citizen”?
    6·2 answers
  • Write a program that asks the user to input
    11·1 answer
  • Should a waiting thread receive priority over a thread first attempting to enter a monitor? What priority scheme, if any, should
    9·1 answer
  • Jared recently sent an email to all the members of his department asking them for their opinions about where the department shou
    11·1 answer
  • Clasifica los documentos comerciales en activo, pasivo o patrimonial para cada operacion:
    14·1 answer
  • What is a field on a table
    13·1 answer
  • Refers to the capacity to form bonds with particular
    11·2 answers
  • Write a recursive function named canmakesum that takes a list of * integers and an integer target value (sum) and returns true i
    6·1 answer
  • find_cow(name, cows) Given a name and a Python list of Cow objects, return the Cow object with the specified name. If no such Co
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!