Tuesday, December 1, 2020

BUBBLE SORT IN DECENDING ORDER

 I will show you how to write a program that will ask the user to give a series of numbers and then the program will sort the given number using a bubble sort algorithm in descending order in C++ programming language.

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 at 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.

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. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.



Program Listing

// bubble_sort.cpp

// Mr. Jake Rodriguez Pomperada,MAED-IT, MIT

// Dev C++

// www.jakerpomperada.com , www.jakerpomperada.blogspot.com

// jakerpomperada@gmail.com

// Bacolod City, Negros Occidental Philippines


#include <cstdlib>

#include <iostream>


using namespace std;


int compare(int, int);

void sort(int[], const int);

void swap(int *, int *);


int compare(int x, int y)

     return(x < y);

}


void swap(int *x, int *y)

{

     int temp;

     temp = *x;

     *x = *y;

     *y = temp;

}


void sort(int table[], const int n)

{

     for(int i = 0; i < n; i++)

     {

          for(int j = 0; j < n-1; j++)

          {

               if(compare(table[j], table[j+1]))

                    swap(&table[j], &table[j+1]);

          }

     }

}


int quantity;

int* tab;


int main(int argc, char *argv[])

{

    cout << "\n\n"; 

cout << "\t\t\tBUBBLE SORT IN DECENDING ORDER\n";

    cout << "\n\t\t Created By: Mr. Jake R. Pomperada, MAED-IT, MIT";

    cout << "\n\n";   

    cout << "\tHow Many Items :=> ";

cin >> quantity;

tab = new int [quantity];

cout << "\n\n";   

for (int i = 0; i < quantity; i++)

{

    int x = i;

    cout << "\tGive value in item no. " << ++x << ": ";

    cin >> tab[i];

}


cout << "\n\tBefore Sorting: ";

cout << "\n\n";

cout << "\t";

for (int i = 0; i < quantity; i++)

{

     cout << tab[i] << " ";

}


cout << "\n\n";

cout << "\tAfter Sorting: \n";

sort(tab, quantity);

cout << "\n\n";

cout <<"\t";

for(int i = 0; i < quantity; i++)

{

     cout << tab[i] << " ";

}

 cout << "\n\n";

    system("PAUSE");

    return EXIT_SUCCESS;

}


No comments:

Post a Comment