Sorting Of Array Through Bubble Sort
![]() |
Sorting Of Array Through Bubble Sort |
Bubble sort is a type of array sorting .
in this sorting there are two methods.
1: in this method user compare 2 consecutive number and swap the first number if 2nd number is lesser than first numbe..
2: in this method user compare first array number with all and greatest number will moved to the most right corner...
from Example..
Program..
#include<iostream>
using namespace std;
int main()
{
int temp , n;
cout<<"Enter number Of Array";
cin>>n;
int arr[n];
cout<<"Array Elemets are ";
for(int y =0 ; y <n ; y++)
{
cin>>arr[y];
}
for(int m=0 ; m<n ; m++)
{
for(int i=0 ; i<n ; i++)
{
int j=i+1;
if(arr[i]>arr[j])
{
temp = arr[i];
arr[i]=arr[j];
arr[j ] = temp;
}
}
}
cout<<"Sorted Array Is";
for(int x =1 ; x <=n ; x++)
{
cout<<arr[x]<<"\t";
}
}
0 comments:
Post a Comment