Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Program to implement Bubble Sort in CPP (C plus plus)

Program to implement Bubble Sort in CPP (C plus plus)

In this tutorial, we will learn about Program to implement Bubble Sort in CPP (C plus plus).

#include<iostream>
 
using namespace std;
 
int main()
{
    int array[50];
	int s;
	int i;
	int j;
	int t;
	
    cout<<"Please enter the size of array: ";
    cin>>s;
    
    cout<<"Please enter the values into array: "; 
    
    for(i=0;i<s;++i)
        cin>>array[i];
        
    for(i=1;i<s;++i)
    {
        for(j=0;j<(s-i);++j)
            if(array[j]>array[j+1])
            {
                t=array[j];
                array[j]=array[j+1];
                array[j+1]=t;
            }
    }
    
    cout<<"Array after sorting is:";
    
    for(i=0;i<s;++i)
        cout<<" "<<array[i];
        
    return 0;
}

Output:

Program to implement Bubble Sort in CPP (C plus plus)

Program to implement Bubble Sort in CPP (C plus plus)