Created
May 2, 2012 03:30
-
-
Save kdmkdmkdm/2573377 to your computer and use it in GitHub Desktop.
selectionsort2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// giSelectionSort.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int x[10]; | |
cout << "Enter ten unsorted integers..." << endl; | |
for(int i = 0; i < 10; ++i) | |
{ | |
cout << "[" << i << "] = "; | |
cin >> x[i]; | |
} | |
cout << endl; | |
// list integers | |
cout << "Unsorted List = "; | |
for(int i = 0; i < 10; ++i) | |
{ | |
cout << x[i] << ", "; | |
} | |
cout << endl; | |
cout << "Sorting..." << endl; | |
// sort integers | |
int temp = 0; | |
for(int i = 0; i < 10; ++i) | |
{ | |
for(int j = 0; j < 10; ++j) | |
{ | |
if(x[i] <= x[j]) | |
{ | |
temp = x[i]; | |
x[i] = x[j]; | |
x[j] = temp; | |
} | |
else | |
{ | |
continue; | |
} | |
} | |
} | |
// list sorted integers | |
cout << "Sorted List = "; | |
for(int i = 0; i < 10; ++i) | |
{ | |
cout << x[i] << ", "; | |
} | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment