Saturday, 24 November 2012

Selection Sort Code for C++


                                Selection     Sort       



   

                  c++      code for selection sort


// selection sort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <math.h>

using namespace std ;


int _tmain(int argc, _TCHAR* argv[])
{
       int fin [11]={6,3,7,1,69,0,23,11,45,5,71 },a,c,m ; // defining array and variables
       {
       for (a=0;a<10;a++) // using for loop
       { c= fin[a];
       int d=a;
       for (m=a;m<=10;m++) // nested for loop
       { if (c>fin[m]) // if condition
       {c=fin[m];d=m;}
       }
       int r=fin[d];
       fin[d]=fin[a];
       fin[a]=r;
       }
       cout<<"SORTED ARRAY IN ASCENDING ORDER"<<endl;
       for(int w=0;w<11;w++) // loop for sorted array output
              cout<<fin[w]<<endl;
}
       getch();
       return 0;
      
      

}

0 comments:

Post a Comment