Joined: Sun May 25, 2008 5:34 pm Posts: 95 Has thanked: 2 time Have thanks: 1 time
Code:
#include <iostream>
using namespace std;
/* * Program to read a list of integers from standard input and print them in * sorted order. This uses a simple selection sort. * * Author: Tom Bennet */
/* * Swap function for sorting. */ void swap(int *a, int *b) { int tmp; /* Exchange temp value. */
tmp = *a; *a = *b; *b = tmp; }
/* * Sort the array. It receives a pointer to the start of the data and the * number of items. */ void sort(int *data, int size) { int minloc; /* Loc of minimum. */
/* * Main program. Reads the integers into an array, sorts them, and * prints them out. */ const int MAX_NUM_INTS = 100; int main() { int ints[MAX_NUM_INTS]; // Where the numbers go.
// Read them in. int i; for(i = 0; i < MAX_NUM_INTS && cin >> ints[i]; ++i); int numints = i;