C++ Programming Blog

 
 
 

Image

#include <iostream.h>
#include <conio.h>
#define MAX 10

class selsort{
    int arr[MAX],n;
    public:
    void getdata();
    void showdata();
    void sortLogic();
};

void selsort :: getdata(){
    cout<<\"How many elements you require : \";
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
}

void selsort :: showdata(){
    cout<<\"\\n--Display--\\n\";
    for(int i=0;i<n;i++)
        cout<<arr[i]<<\"   \";
}

void selsort :: sortLogic(){
    int temp,min;
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i+1;j<n;j++){
            if(arr[min] > arr[j]){
                min=j;
            }
        }
        temp = arr[min];
        arr[min] = arr[i];
        arr[i] = temp;
        cout<<\"\\n arr[min] = \"<<arr[min]<<\"  arr[i] = \"<<arr[i];
    }
}

void main(){
    clrscr();
    cout<<\"\\n*****Selection Sort*****\\n\";
    selsort obj;
    obj.getdata();
    obj.sortLogic();
    obj.showdata();
    getch();
}

    Related Post:
  1. Program to illustrate the use of parameterless function

  2. Program that performs array operations like insert,delete, search, sort, merge and display

  3. Program to fill a Circle using Scan-Line Circle Fill Algorithm

  4. Program of Education System that maintains Institute Database using multilevel inheritance

  5. Program to illustrate static member functions

  6. Program to illustrate unary operator (increment operator) overloading without return type

  7. Program that provides an example of call by value for functions

  8. Program for Operator Overloading and Friend Function concept

  9. Program to swap two variables using header file swap.h

  10. Program to show the implementation of None-or-All String Clipping Strategy (Text Clipping Example)

  11. Program to copy n number of characters from one string to another at position p

  12. Program to show the implementation of Hashing with Insert, Delete and search functionality using double-ended Linked List

  13. Program to illustrate the binary operator(-) overloading without creating an object of that class

  14. Program to create a queue using static memory allocation

  15. Program that computes the n_th term of the fibonacci series using recursion

  16. Program for election contest among five candidates

  17. Program to illustrate object initialization and assignment by default member wise copy

  18. Identifer recognisition Integer Unsigned real number with optional integer part

  19. Program to draw a 3D Bezier Surface for MxN control points

  20. Program that computes and display the square of first ten integers. (using for loop)

 
 
Didn't find what you were looking for? Find more on Program to perform selection sort