Advertisement
SalimFadhil

selection C++

Mar 26th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<iostream.h>
  2. class selection{
  3. int * ar , size;
  4.  
  5. public:
  6.     void getInput();
  7.     void s_sort();
  8.     void display();
  9. };
  10.  
  11. void selection::getInput(){
  12.     cout << "Enter the size of array:\n";
  13.     cin >> size;
  14.     ar = new int[size];
  15.  
  16.     cout << "Enter the data into array:\t";
  17.     for(int i=0;i<size;i++)
  18.     cin >>ar[i];
  19. }
  20.  
  21. void selection::s_sort(){
  22.     int t;
  23.     for(int k=0; k<size-1; k++)
  24.     for(int m=k+1; m<size; m++)
  25.     if(ar[k] > ar[m]){
  26.         t = ar[k];
  27.         ar[k] = ar[m];
  28.         ar[m] = t;
  29.     }
  30. }
  31.  
  32. void selection::display(){
  33.     cout << "Data of array after sorting = \n";
  34.     for(int i=0;i<size;i++)
  35.     cout << ar[i] << endl;
  36. }
  37.  
  38. int main(){
  39.     selection *s = new selection();
  40.     s->getInput();
  41.     s->s_sort();
  42.     s->display();
  43.    
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement