Saturday, October 24, 2020

Bubble Sort in C++

 In this articles, I will show you how to write a bubble sort program which uses C++ as our programming language using for loop statements and arrays data structures.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.


My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.
dfdfffdfd



My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking and Arduino Project development at a very affordable price.






Program Listing

// addition_subtraction.cpp
// Jake Rodriguez Pomperada, MAED-IT, MIT
// www.jakerpomperada.blogspot.com / www.jakerpomperada.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines

#include <iostream>

using namespace std;

int main()
{
    int arr[100],n=0;
    int i=0,j=0,temp=0;

    cout <<"\n";
    cout <<"\t\tBubble Sort in C++\n\n";
    cout <<"\t  Jake R. Pomperada,MAED-IT,MIT";
    cout <<"\n\n";

cout<<"\tGive the size of array: ";
cin>>n;
    cout <<"\n\n";

for(i=0;i<n;++i) {
        cout<<"\tGive Array Element Value No."
         <<(i+1)<< " : ";
cin>>arr[i];
}

cout <<"\n\n";

cout <<"\tOriginal Arrangement of Values";
cout <<"\n\n";
cout <<"\t";
for(i=0;i<n;++i) {
cout<<" "<<arr[i];
}

for(i=1;i<n;++i)
{
for(j=0;j<(n-i);++j)
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
    cout <<"\n\n";
cout<<"\tArray Arrangement After Bubble Sort";
cout <<"\n\n";
cout <<"\t";
for(i=0;i<n;++i) {
cout<<" "<<arr[i];
}
    cout <<"\n\n";
    cout <<"\tEnd of Program";
    cout <<"\n";
}



No comments:

Post a Comment