google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: C++ program to implement Bubble Sort.

Friday, December 27, 2019

C++ program to implement Bubble Sort.

C++ program to implement Bubble Sort.

#include

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 "< cin>>arr[i];
}

BubbleSort(arr, n);
  cout<<"\nSorted Data ";
for (i = 0; i < n; i++)
        cout<<"->"<
return 0;
}

No comments:

Post a Comment

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...