C++ code for bubble sort


C++ code for bubble sort

This is C++ example code for the bubble sort

#include <cstdlib>
#include <iostream>
#include <conio.h>


using namespace std;
void bubblesort(int dataset[], int n){
 int i,j;
 for(i=0;i<n;i++)
  for(j=n-1;j>i;j--)
  if(dataset[j]<dataset[j-1])
  {
    int temp=dataset[j];
    dataset[j]=dataset[j-1];
    dataset[j-1]=temp;
}

}

int main(){
  int arr[5]={23,2,3,34,6}; //unsorted data set
  bubblesort(arr,5); //sorting process using bubble sort
  for(int i=0;i<5;i++)
     cout<<arr[i]<<"\t"; //after sorting


getch();
return 0;

}


Comments

Royal Blood comment

 Royal Blood

nicely written implementation of bubble sort algorithm but it is missing explanation, if anyone wants explanations then they could find it there:

http://www.hellgeeks.com/bubble-sort/


2014-08-28
Royal Blood comment

 Royal Blood

nicely written implementation of bubble sort algorithm but it is missing explanation, if anyone wants explanations then they could find it there:

http://www.hellgeeks.com/bubble-sort/


2014-08-28
parmeshwar raut comment

 parmeshwar raut

babbul soart


2014-02-18
parmeshwar raut comment

 parmeshwar raut

babbul soart


2014-02-18



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.