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.
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.
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.
Last edited by JoshR; 05-01-2005 at 12:28 PM.
Here a piece of aprogram I,ve made. You should probably get a sence of how to use the sorting techniques:
You need so search cprogramming.com or google and find out for yourself which sorting technique is the best for the situation.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]); } }
Last edited by JoshR; 05-01-2005 at 01:02 PM.
nvm...
Last edited by JoshR; 05-01-2005 at 01:01 PM.
Ooops wasnt thinkin, didnt realize it could be his homework.
Last edited by JoshR; 05-01-2005 at 01:04 PM.