Professional Documents
Culture Documents
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.
Facebook Twitter
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.
All we have done is that we have simply transform the algorithm of Bubble sort in the in C++ programming language.
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.
//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;
}
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.
Facebook Twitter
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
Publish Preview
Follow Us
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Most Popular
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 Programs (6)
C Tutorial (2)
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
SOFTOSET FOLLOW US
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD