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
The function ________ comprises one or more statements that are executed when the function is called.
spin [16.1K]

Answer:

Option B(Body) is the correct answer for the above question.

Explanation:

The function is a defined processor of some specific task, which is used to perform some action of the task. The function is of two types one is predefined, which is defined by the compiler and, the other is user-defined, which is defined by the programmer. Any user-defined function has three parts--

  • Function prototype: It states the type of function.
  • Function body: It holds the collection of instruction that needs to perform by the function.
  • Function call: From where the function is called.

The above question asked about the term, which holds the statement of the function and that term is function Body, which is defined above. So the answer body, which is stated from the option 'B'. Hence 'B', is the correct option while the other is not because--

  • Option 'A' states about the header, which is not the part of the function
  • Option 'C' states about data type, which defines the types of data.
  • Option 'D' states none of these, but the answer is option B.
  • Option 'E' states about the definition, which is not the correct answer.
5 0
3 years ago
Compare and contrast the TwoFish encryption algorithm with the DES and AES algorithms. In your comparison be sure to compare and
zheka24 [161]

Answer:

The comparison is done based on their basic, principle, plaintext, key size, rounds, rounds name, security and speed. See the attached document.

Explanation:

The the attachment

8 0
4 years ago
JavaScript uses which property to change the current content of HTML elements?
solong [7]

Answer:

innerHTML

Explanation:

3 0
4 years ago
What are the difference between requests management to problem management??​
BaLLatris [955]

Answer:

Problem management is a practice focused on preventing incidents or reducing their impact.

Request Management is the systematic handling of the tasks required for a variety of different internal or external requests using workflow automation, business rules, and analytics. Request management problems manifest in a variety of ways in any organization: Slow request turnaround times.

Explanation:

4 0
3 years ago
1. USES COMPUTER TO EXPRESS HIMSELF ARTISTICALLY
Inessa05 [86]

Answer:

  1. A
  2. D
  3. D
  4. C
  5. C
  6. D
  7. B
  8. C
  9. D
  10. A
  11. D
  12. D
  13. D
  14. D
  15. D
  16. C
  17. A
  18. B
  19. B
  20. A

Explanation:

IT WAS A PLEASSURE

5 0
3 years ago
Other questions:
  • OBJECTIVE This project will familiarize you with the use of pthreads, pthread mutexes and pthread condition variables. Your prog
    9·1 answer
  • In the CIA Triad, "Confidentiality" means ensuring that data is
    9·1 answer
  • I need help on this it's not really a subject it's drivers edd
    13·1 answer
  • List three components of a computer system​
    10·1 answer
  • True/False: The American Standard Code for Information (ASCII) is a code that allows people to read information on a computer.
    9·2 answers
  • Inaccurate __________ is the number-one reason why many small businesses go bankrupt.
    5·1 answer
  • Which of the following statements about version control are true? Select 3 options.
    7·2 answers
  • Which of the following allows computers to communicate with each other? RAM NIC Hard drive Floppy disk
    11·1 answer
  • Draw at least 15 fabric/garment care labels on a piece of paper to be submitted the following week
    5·1 answer
  • What are the advantages of cloud computing over computing on premises?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!