Program of Bubble Sort in Array

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

/*PROGRAM OF BUBBLE SORT IN ARRAY*/

#include<iostream.h> #include<conio.h> void BubbleSort(int[],int); void main() { int AR[50],N; clrscr(); cout<<"How many elements do you want to create Array with?(max.50)..."; cin>>N; cout<<"\nEnter Array Elements...\t"; for(int i=0;i<N;i++) cin>>AR[i]; } BubbleSort(AR,N); cout<<"\n\nThe Sorted Array is as shown below...\n"; for(i=0;i<N;i++) cout<<AR[i]<<"\n"; cout<<endl; void BubbleSort(int AR[],int size) int tmp,ctr=0; for(int i=0;i<size;i++) for(int j=0;j<(size-1)-i;j++) if(AR[j]>AR[j+1]) tmp=AR[j]; AR[j]=AR[j+1]; AR[j+1]=tmp; cout<<"Array after iteration-"<<ctr++<<"-is:\t"; for(int k=0;k<size;k++) cout<<AR[k]<<" "; cout<<endl; } }

} { { { { }

OUTPUT
How many elements do you want to create Array with?(max.50)... 4 Enter Array Elements... 7 3 8 2 Array after iteration-1-is: 3 7 8 2 Array after iteration-2-is: 3 7 8 2 Array after iteration-3-is: 3 7 2 8 Array after iteration-4-is: 3 7 2 8 Array after iteration-5-is: 3 2 7 8 Array after iteration-6-is: 2 3 7 8 The Sorted Array is as shown below... 2 3 7 8

You might also like