C++ Bubble Sorting and Comparing -
i've done bit of code try , sort list of movies either year, name or votes when run application not sort. wondering went wrong. believe might have movie movie.
update: i've fixed somewhat, sorting first 10 or 20 items on list not sort rest. i've checked cout if there wrong loops , seems go 0-248 fine.
enum moviesortorder { by_year = 0, by_name = 1, by_votes = 2 }; int movie::comparebyvotes(movie m) { if (m.get_votes() == this->get_votes()) { return 0; } else if (m.get_votes() > this->get_votes()) { return 1; } else { return -1; } } int movie::comparebyyear(movie m) { if (m.get_year() == this->get_year()) { return 0; } else if (m.get_year() > this->get_year()) { return 1; } else { return -1; } } int movie::comparebyname(movie m) { string = m.get_name(); string b = this->get_name(); if (a[0] = b[0]) { return 0; } else if (a[0] > b[0]) { return 1; } else if (a[0] < b[0]) { return -1; } } int movie::compareto(movie m, moviesortorder n) { if (n == 0) { return comparebyyear(m); } else if (n == 1) { return comparebyname(m); } else if (n == 2) { return comparebyvotes(m); } } bool movielist::movelargesttoend(moviesortorder n) { bool changed = false; (int = 0; < last_movie_index; i++) { //cout << << endl; if (movies->compareto(movies[i], n) > movies->compareto(movies[i + 1], n)) { swap(movies[i], movies[i + 1]); changed = true; } } return changed; } void movielist::bubblesort(moviesortorder n) { (int = 0; < last_movie_index; i++) { if (!movelargesttoend(n)) { return; } } }
this line problem:
if (a[0] = b[0])
it assignment, not comparison. true/false comes value of b[0]
.
that first if
in movie::comparebyname(movie m)
Comments
Post a Comment