Logo 
Search:

Visual C++ Articles

Submit Article
Home » Articles » Visual C++ » Homework HelpRSS Feeds

Selection Sort in C++

Posted By: Falak Khan     Category: Visual C++     Views: 7213

Code for Selection Sort in C++ in Visual C++

#include<iostream>
#include<iomanip>
usingnamespace std;
int loc=0;
int min(int sort[],int k);
int main()
{
    char ch;
    do
    {
          int select[8],k,c,temp;
          cout<<"enter 8 elements of array to sort"<<endl;
          for (int i=0;i<8;i++)
          {
               cin>>select[i];
          }
          cout<<endl;
          for(k=0;k<8;k++)
          {
               c=min(select,k);   
               temp=0;
               temp=select[k];
               select[k]=select[loc];
               select[loc]=temp;
          } 
         cout<<"array after sort"<<endl;
         for ( i=0;i<8;i++)
         {
              cout<<select[i]<<'\t';
         }
         cout<<endl;
         cout<<"do you want to sort more array"<<endl;
         cin>>ch;
    }
    while(ch!='n');
      return 0;
}


int min(int sort[],int k)
{
           int mini;
           mini=sort[k];
           loc=k;
          for(int j=k+1;j<=7;j++)
          {
               if(mini>sort[j])
               {
                   mini=sort[j];
                   loc=j;
                   
               }
          }
          return mini;
}
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Selection Sort in C++ Or get search suggestion and latest updates.

Falak Khan
Falak Khan author of Selection Sort in C++ is from Pakistan.
 
View All Articles

 

Other Interesting Articles in Visual C++:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!