Posts Tagged ‘bubble sort’

Bubble Sort

Posted: 9 June 2008 in Puisi
Tags: ,

#include <iostream.h>
#include <conio.h>
#define MAX 10

class bubsort{
int arr[MAX],n;
public:
void getdata();
void showdata();
void sortLogic();
};

void bubsort :: getdata(){
cout<>n;
for(int i=0;i>arr[i];
}

void bubsort :: showdata(){
cout<<“\n–Display–\n”;
for(int i=0;i<n;i++)
cout<<arr[i]<<” “;
}

void bubsort :: sortLogic(){
int temp;
for(int i=0;i<n;i++){
for(int j=0,exchange=0;j arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
exchange++;
cout<<“\n arr[j] = “<<arr[j]<<” arr[j+1] = “<<arr[j+1];
}
}
cout<<endl;
if(exchange==0)
break;
}
}

void main(){
clrscr();
cout<<“\n*****Bubble Sort*****\n”;
bubsort obj;
obj.getdata();
obj.sortLogic();
obj.showdata();
getch();
}