Hey, I'm writing a program for class and it needs to accept input of numbers from three different files and sort them from smallest to largest. I'm not allowed to use arrays, and have no idea what logic to use. I can get the file in/out stuff no problem, but don't know how to do the sorting. Any help would be great. Thanks
std::list<int> mylist; // in the standard c++ lib...
std::list<int>::iterator it;
// open the frist file
// populate the list.
// open the second
// append to the list...
// open the third
// append to the list....
//in <algorithms> // more of the cpp std lib..
std::sort(mylist.begin(), mylist.end());
//or
std::stable_sort(mylist.begin(), mylist.end());
// then print the list...
If you need to write the sort by hand look up Bubble sort, insertion sort and/or quick sort algorithms. They have been around for twenty-plus years. You didn't say how to you needed to achieve things.
That stuff is in the reference sections of this site, and give examples on how to use them.
If I didn't have an array I would be using. CS140 doesn't tell me anything..
If I didn't have the STL.
I would use a linked list and an insertion sort. I don't know what topics you have covered in your class so I don't know what you know or you don't know. When I took cs150, I knew most of these algorithms and just needed apply to the language.
The basics of an Insertion sort I have a list of some form and I search for the point I would go before.
The other method is to Use a Tree, which keeps things easier to maintain. Trees have a node with right and left. Anything that goes right, is greater than the current node and left is the anything less than the node. Neither of them are arrays and deal with pointers, which I don't know if you have covered or not.
Most of these have documentation on the web in some form, even wiki might give you some detail on them.
Do you know what a class or struct is? Do you know what a pointer is?