What's your final output going to look like?
Because if it's Author/Title/Publication date then you can just alphabatize the author by last name.
Here's the function for that using bubblesort.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
void bubblesort(string list[],int count)
// Sort an array of strings into descending order.
// Parameters:
// list – array of strings to be sorted
// count – (integer) number of values in the array
// Value passed back: sorted list
{
int i; int j;
string temp;
for (i=0; i < n-1; i++)
for (j=0; j < n-(i+1); j++)
if (list[j] > list[j+1])
{
temp = list[j];
list[j] = list[j+1];
list[j+1] = temp;
}
}
|
How this works:
Sorting – rearranging a collection of values into a logical order
sorting orders
ascending – smallest to largest (for strings, alphabetical order)
descending – largest to smallest
Bubblesort sorting strategy
decide on desired sorting order (ascending or descending)
perform the following
1) move through the list comparing adjacent values
2) if adjacent values are out of desired order, interchange them
3) when a complete pass through the list has been made, the smallest
(largest) value will have "bubbled" to its proper location
4) repeat steps 1 and 3 ignoring the already sorted values (requires length-1
passes through the list)