code for bubble sort in c++ code example

Example 1: code for bubble sort in c++

void bubbleSort (int S[ ],  int length) {
	bool isSorted = false;
	while(!isSorted)
   	{
		isSorted = true;
		for(int i = 0; i S[i+1])
           	     {
			int temp = S[i];
			S[i] = S[i+1];
     	       		S[i+1] = temp;
            		isSorted = false;
           	      }
      	}
      	length--;
}
}

Example 2: code for bubble sort in c++

void bubbleSort (int S[ ],  int length) {
	bool isSorted = false;
	while(!isSorted)
   	{
		isSorted = true;
		for(int i = 0; i S[i+1])
           	     {
			int temp = S[i];
			S[i] = S[i+1];
     	       		S[i+1] = temp;
            		isSorted = false;
           	      }
      	}
      	length--;
}
}

Example 3: Bubble Sort C++

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;


int main(){
    int n,temp,c=0;
    cin >> n;
   int a[n];
    for(int i=0;i>a[i];
    }
    for(int i=0;ia[j+1])
                {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
                c++;
            }
        }
    
    if(c==0)
        {
        break;
    }}
    cout<<"Array is sorted in "<

Example 4: bubble sort program in c++

cout<<"\n Hello World ";

Tags:

Misc Example