I've been attempting to write a program to keep track of my workouts and do a number of different functions. The program uses the STL list to store a struct of data on my workout. Im having trouble thinking of an algorithm to sort my list and display it according to the date. The struct holds the date as a string the format (00/00/00). Could anyone help get me started on how i would go about sorting the list?
if a little visual help is needed, think of it like this, i have 4 objects in my linked list, these have the dates:
04/15/12
04/07/12
05/02/12
04/26/12
How would i sort these in a function and display them?
Maybe parse the string on input and store the month, day and year as ints.
Edit: If you want to keep them as strings I suppose you could just compare the individual char's.
So i got the code working, which i really appreciate it. But how would i sort this if the string was a part of a struct in a list of structs? Im guessing i might need to make a temp list to sort those dates, then somehow sort the main list using the second list? Thanks if you can help further guys!
I would overload operator< in the struct or write a comparetor function and only do comparison on the string member. And use std::sort to do the soring, if you write a comparator you have to pass it to sort()