# Putting numbers in order

• 05-01-2005
Queatrix
Putting numbers in order
Is there a way to take 100 random numbers and print them all out in order from 1 to 99?
(I can randamize, just not put them in order.)
Thanks, August.
• 05-01-2005
Thantos
Yes its called sorting
• 05-01-2005
JoshR
Ya, you can implement any type of "sort" technique, I just did this about 2 weeks ago. Search google for bubble sort, insertion sort, selection sort, merge sort, and quick sort. Any of those will get the job done, however bubble is the slowest but for 100 numbers it doesnt really matter. You can google it to see some code, if you want I can show you an example. But the precondition of each sort, is that the numbers are in an array.
• 05-01-2005
Queatrix
I am always open to examples. ;)
• 05-01-2005
JoshR
Here a piece of aprogram I,ve made. You should probably get a sence of how to use the sorting techniques:

Code:

```void testSort() {   ifstream infile("Test.txt", ios::in);   string line;   char letter;   int count = 0;   vector< string > names(5);     cout << "Testing string sort..." << endl << endl;     while (infile.get(letter) && count < 5)   {       line = "";       while (letter != '\n' && !infile.eof())       {          line += letter;         infile.get(letter);       }       names[count++] = line;   }     print (names);   selectionSort(names);     cout << endl;   print (names); } void swap (string &a, string &b) {       string temp = a; a = b; b = temp; } void selectionSort (vector< string > &list) {   int flag;     for (int outer = 0; outer < list.size(); outer++)   {       flag = outer;       for (int inner = outer + 1; inner < list.size(); inner++)         if (list[inner] < list[flag])             flag = inner;       swap(list[outer], list[flag]);   } }```
You need so search cprogramming.com or google and find out for yourself which sorting technique is the best for the situation.
• 05-01-2005
JoshR
nvm...
• 05-01-2005
Thantos
Josh lets not do his homework for him
• 05-01-2005
JoshR
Ooops wasnt thinkin, didnt realize it could be his homework.