Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created May 2, 2012 03:30
Show Gist options
  • Save kdmkdmkdm/2573377 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/2573377 to your computer and use it in GitHub Desktop.
selectionsort2
// 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