Reputation: 19
I have a Movie class set up and I am trying to create a function to sort an array of movies by release date and then by rating. I have 7 movies in a text document getting stored into my array and getter functions at the ready but I am having trouble converting what little I know about sorting an array of ints into an array where I need to sort strings and then doubles.
Here is my code:
string Movie::getReleaseDate() {
return releaseDate;
}
double Movie::getRating() {
return rating;
}
void sortByDateRating(Movie movies[], int SIZE) {
int i;
int j;
int temp;
for (i = 1; i < SIZE; ++i) {
j = i;
while (j > 0 && movies[j] < movies[j - 1]) {
temp = movies[j];
movies[j] = movies[j - 1];
movies[j - 1] = temp;
--j;
}
}
}
I plan to call this function from a switch case I have in main. Thanks ahead of time.
Upvotes: 1
Views: 322