Computer Science, asked by gayana1804, 4 months ago

write a c++ program sort elements using bubble sort​

Answers

Answered by mad210202
0

Answer:

c++ program sort elements using bubble sort​

Explanation:

#include <iostream>

 

using namespace std;

 

void BubbleSort (int arr[], int n)

{

int i, j;

for (i = 0; i < n; ++i)

{

 for (j = 0; j < n-i-1; ++j)

 {

  if (arr[j] > arr[j+1])

  {

   arr[j] = arr[j]+arr[j+1];

   arr[j+1] = arr[j]-arr[j + 1];

   arr[j] = arr[j]-arr[j + 1];

  }

 }

}  

}  

 

int main()

{

int n, i;

cout<<"\nEnter the number of data element to be sorted: ";

cin>>n;

 

int arr[n];

for(i = 0; i < n; i++)

{

 cout<<"Enter element "<<i+1<<": ";

 cin>>arr[i];

}

 

BubbleSort(arr, n);

 

cout<<"\nSorted Data ";

for (i = 0; i < n; i++)

       cout<<"->"<<arr[i];

 

return 0;

}

Answered by masterankur9779
0

Hi mate please refer to given website Because I don't know the Answer

Sorry ♥️

But I think that it would help you

Attachments:
Similar questions