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();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s