fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int UnList[10];
  7. int SList[10];
  8. int i,j,n,x,s;
  9. int nVal; // Ask user to insert the values for the Unsorted List.
  10. cout << "Please insert 10 integers numbers:" << endl;
  11. for(i=0; i< 10; i++){
  12. cout << "[" << i <<"]" << "= ";
  13. cin >> nVal;
  14. cout << endl;
  15. UnList[i]={nVal};
  16. }// end of loop for storing the values.
  17. //Display the Unsorted List
  18. cout << "Unsorted List: ";
  19. for(j=0; j<10; j++){
  20. cout << UnList[j] << ",";
  21. }
  22. cout << endl;
  23. cout << "Sorting ..."<< endl;
  24. //Selection Sort Algorithm
  25. for (n = 0; n <10; n++){
  26. for (x=0; x<9; x++){
  27. if (UnList[x] > UnList[x+1]){
  28. s = UnList[x+1];
  29. UnList[x+1] = UnList[x];
  30. UnList[x] = s;
  31. }
  32. }
  33. //SList[n] = UnList[n];
  34. }// end of the Linear Search method...
  35. //end of the Sorting Method...
  36.  
  37. //Display Sorted List
  38. cout << "Sorted List: ";
  39. for(i = 0; i<10; i++){
  40. cout << UnList[i] << " ";
  41. }
  42. }
Success #stdin #stdout 0s 2900KB
stdin
10
7
2
20
3
5
6
11
18
33
stdout
Please insert 10 integers numbers:
[0]= 
[1]= 
[2]= 
[3]= 
[4]= 
[5]= 
[6]= 
[7]= 
[8]= 
[9]= 
Unsorted List: 10,7,2,20,3,5,6,11,18,33,
Sorting ...
Sorted List: 2 3 5 6 7 10 11 18 20 33