need coding for bubble sort

2 replies [Last post]
ash_rock
Offline
Last seen: 10 years 3 weeks ago
Joined: 2010-01-08
bOt Points: 114

shashwat
Offline
Last seen: 1 year 31 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Bubble Sort

#include <iostream.h>


void bubbleSort(int x[],int length)//Bubble sort function 

{

for(int i=0;i<length;i++)

{

for(int j=0;j<(length-1);j++)

{

if(x[i]>x[j])

{

int temp=x[i]; //swap 

x[i]=x[j];

x[j]=temp;

}


}


}


}

int main()

{

int i,x[10]={12,44,55,34,7,10,3,30,20,15};

cout<<"Elements of the array are as follows\n";

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

cout<<x[i]<<", ";

cout<<x[i]<<"\n";

bubbleSort(x, 10);

cout<<"Elements of the array after BUBBLE SORTING are as follows\n";

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

cout<<x[i]<<", ";

cout<<x[i]<<"\n";

return 0;

 

Founder and Admin

ash_rock
Offline
Last seen: 10 years 3 weeks ago
Joined: 2010-01-08
bOt Points: 114
thnx alot dear

thnx alot dear