C++ Programming Tutorial

 
 
 
 

Image

 # include <iostream.h>
 # include    <conio.h>

 void bubble_sort(int [],const int);

 int main( )
 {
    clrscr( );
    textmode(BW80);

    const int array_size=10;

    int array[array_size]={0};

    cout<<\"\\n ******************************************************************************\"<<endl;
    cout<<\" ********************************  Bubble Sort  *******************************\"<<endl;
    cout<<\" ******************************************************************************\"<<endl;

    cout<<\"\\n * Array size = 10\"<<endl;
    cout<<\" * Data Type = int\"<<endl;

    gotoxy(1,24);
    cout<<\" ******************************************************************************\";
    gotoxy(1,25);
    cout<<\" ******************************************************************************\";

    gotoxy(1,10);
    cout<<\" Enter the array : \"<<endl<<endl;

    for(int count_1=0;count_1<array_size;count_1++)
    {
       cout<<\"\\t Element[\"<<count_1<<\"] = \";
       cin>>array[count_1];
    }

    bubble_sort(array,array_size);

    gotoxy(40,10);
    cout<<\" Sorted Array : \";

    for(int count_2=0;count_2<array_size;count_2++)
    {
       gotoxy(50,12+count_2);
       cout<<\"Element[\"<<count_2<<\"] = \"<<array[count_2]<<endl;
    }

    getch( );
    return 0;
 }



 //---------------------------  bubble_sort( )  --------------------------//


 void bubble_sort(int array[],const int size)
 {
    for(int i=0;i<(size-1);i++)
    {
       for(int j=(size-1);j>=(i+1);j--)
       {
      if(array[(j-1)]>array[j])
      {
         int temp=array[(j-1)];

         array[(j-1)]=array[j];
         array[j]=temp;
      }
       }
    }
 }

    Related Post:
  1. Program to help Umar in this task. Represent each city by one lowercase character. Thus, you can have at most 26 different cities to visit....

  2. Program to illustrate the Merge Sort

  3. Program to illustrate the use of call-by-value method in functions

  4. Program to illustrate an example of Inheritance

  5. Program to construct Newtons Divided Difference Interpolation Formula from the given distinct data points and estimate the value of the function

  6. Library system using pointers

  7. Mini Project School Management Application

  8. Program to illustrate the binary operator(+) overloading by creating a new object

  9. Program to estimate the Integral value of the function at the given points from the given data using Trapezoidal Rule

  10. Program that defines template of vector class that provides modify and multiplication facility

  11. Program to fill a Circle using Scan-Line Circle Fill Algorithm using Polar Coordinates

  12. Program to count number of words, lines and characters in given string

  13. Program to read a Non-Linear equation in one variable, then evaluate it using Modified False-Position Method and display its kD accurate root

  14. Program of class to basic conversion

  15. Program of singly link list with different functionalities

  16. Program to illustrate the implementation of 3D Rotation Transformation along z-axis

  17. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

  18. Program that reads marks of a students and computes and displays grade

  19. Program that provides an example of static variables in class

  20. Program to draw a Triangle

 
 
Didn't find what you were looking for? Find more on Program to show the implementation of the Bubble Sort Algorithm