You are on page 1of 11

 

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other
interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming
languages. SoftOSet is the hub of the informative and research based articles.

Home  C plus plus programs

Bubble Sort Program in C Plus Plus


 Ehsan Malik  June 06, 2020  0 Comments

  Facebook  Twitter   

Bubble Sort Program in C Plus Plus

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Bubble sort is an efficient sorting technique in the data structure using which you can efficiently sort the data in
ascending or descending order.

In this article we will develop a C ++ program of bubble sort which will take the data from the user and sort it to the
ascending order.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You can also sort the data in the descending order using bubble sort by making the minor changes in the program code.

How this Program Works

All we have done is that we have simply transform the algorithm of Bubble sort in the  in C++ programming language.

The algorithm of bubble sort is as under.

Algorithm of Bubble Sort

Bubble (DATA, N)
Here DATA is an array with N elements. This algorithm sorts the elements in DATA.
1. Repeat Steps 2 and 3 for K=1 to N-1.
2. Set PTR:=1. [Initializes pass pointer PTR.]
3. Repeat while PTR<=N-K: [Executes pass.]    
a. If DATA[PTR]>DATA[PTR+1], then:                                                                             Interchange DATA[PTR] and
DATA[PTR+1].                                       [End of If structure.]
b. Set PTR:=PTR+1.                                                                                                    [End of inner
loop.]                                                                                                                     [End of Step 1 outer loop.]  
4. Exit.                                                                               

                                                      
                 
How this Program Behave

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
This program will ask the user to enter the numbers to be sorted. User will enter the numbers program will sort these
numbers.

Program of Binary Search

//softoset.blogspot.com
//Bubble Sort
#include<iostream>
using namespace std;
#define MAX 100
int main()
{
            int Data[MAX],size;
            cout<<"How many Element You Want to insert "<<endl;
            cin>>size;
            cout<<"Enter Elements "<<endl;
            for(int i=1;i<=size;i++)
            {cout<<"["<<i<<"]"<<" = ";cin>>Data[i];
            }
            for(int j=1;j<size-1;j++)
            {
                        int ptr=1;
                        while(ptr<=size-j)
                        {
                                    if(Data[ptr]>Data[ptr+1])

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
                                    {
                                                int temp=Data[ptr];
                                                Data[ptr]=Data[ptr+1];
                                                Data[ptr+1]=temp;
                                    }
                                    ptr++;
                        }
            }
            cout<<"Sorted Eements"<<endl;
                        for(int i=1;i<size+1;i++)
            {cout<<"["<<i<<"]"<<" = "<<Data[i]<<endl;;
            }
            return 0;
}

 Output of Program Binary Search

This is the sample output from the program on the first run.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
You can clearly see that this program has successfully sort the data in ascending order.

SoftOSet.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Reset Your Technology.

Tags C plus plus programs Data Structure

  Facebook  Twitter   

You might like Show more

Bubble Sort Program in C Plus Plus Binary Search Program in C Plus Plus Conversion of Infix to Postfix Expression
 June 06, 2020  June 06, 2020 Program in C Plus Plus
 June 06, 2020

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Post a Comment

Feel Free to Comment Us

Enter your comment...

Comment as: Google Accoun

Publish Preview

 Previous Post Next Post 

Follow Us

 1.5k  3.1k  2.7k

 500  1.8k  4.2k

  

  

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Most Popular

Currency Converter Program in C++


 May 04, 2020

Program in C++ to Calculate Fractions


 April 23, 2020

C++ Program to find Number of Days in Month


 April 29, 2020

Follow by Email
Get all latest content delivered straight to your inbox.

Email Address

Subscribe

Comments

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
razzaq
I have a similar interest this is my page read ...

sobia
I encourage you to read this text it is fun de...

Categories

Articles (5)

Books (2)

C Plus Plus Programs (36)

C Programs (6)

C Tutorial (2)

Data Structure (4)

Java (2)

Python (1)

Site Views

6,568

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Main Tags

Articles Books C plus plus programs C Programs C Tutorial Data Structure Java Python

Recents in Bitcoin

Error: No Results Found

SOFTOSET FOLLOW US

Reset Your Technology. We are passionate to deliver the best


    
and qualified content to our visitors.

Home Disclaimer Terms and Conditions FAQs


Copyright (c) 2020 SoftOSet All Right Reseved

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

You might also like