Selection Sort in C++

Submitted by: 
Language: 
Visitors have accessed this post 870 times.

Selection Sort in C++. By this method, you can easily sort a for loop code and array. Below are the sample codes:

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int arraylength,num[1000],num1,d,num2=0;
  7. cout<<"Enter the total no. of element: ";
  8. cin>>arraylength;
  9.  
  10. for(int i=0;i<arraylength;i++)
  11. { cout<<"Enter No."<<i+1<<": ";
  12. cin>>num[i],num[d]; }
  13.  
  14. { cout<<" \n" << endl; }
  15. for(int d=0;d<arraylength;d++){
  16. cout<<num[d]<<" " << "\n" << endl;
  17.  
  18.  
  19. cout<<"UNSORTED ARRAY : ";
  20. for(int i =0;i<arraylength;i++){
  21. cout<<num[i]<<" ";
  22. }
  23.  
  24.  
  25. cout<<endl<<"SORTED ARRAY : ";
  26.  
  27. for(int a=0; a<arraylength-1;a++){
  28. for(int b=0; b<arraylength-a-1;b++){
  29. if(num[b]<num[b+1]){
  30. num1=num[b];
  31. num[b]=num[b+1];
  32. num[b+1]=num1;
  33. }
  34. }
  35. }
  36. for(int r=0;r<arraylength;r++){
  37. cout<<num[r]<<" ";
  38. }
  39. }
  40. return 0;
  41. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Thanks author this project will help for my project. more usefull

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.