Thanks,

Ipush

Driver where it is called:

//Quick Sort cout << "Sorting movies by Title with Quick Sort." << endl; cout << endl; quickSort(movies); cout << "After sort:" << endl; displayTitle(movies);

Quick sort:

#include <iostream> #include <string> #include "utilities.h" #include "Movie.h" #include "quickSort.h" using namespace std; void quickSort(vector<Movie> &a) { //------------------------------------------------------ // driver subprogram to sort an entire vector into // ascending order with quickSort. //------------------------------------------------------ quickSort(a, 0, a.size()-1); } //---------------------------------------------------------------------------- // void quickSort(vector<Movie> &a, int left, int right) { //------------------------------------------------------ // quickSort(): a recursive partitioning-based sort //------------------------------------------------------ if (left < right) { int k = partition(a, left, right); quickSort(a, left, k); quickSort(a, k+1, right); } } //---------------------------------------------------------------------------- // int partition(vector<Movie> &a, int left, int right) { //------------------------------------------------------ // partition(): rearrange a into 3 sublists: // - a sublist a[left] ... a[j-1] of values at most a[j] // - a sublist a[j], and // - a sublist a[j+1] ... a[right] of values at least a[j] //------------------------------------------------------ string pivot = a[left].getTitle(); int i = left - 1; int j = right + 1; do { do { j-- ; } while (a[j].getTitle().compare(pivot) != -1) ; do { i++ ; } while (a[i].getTitle().compare(pivot) != 1); if (i < j) exchange(a[i], a[j]); } while (i < j); return j; } int partitionYear(vector<Movie> &a, int left, int right) { //------------------------------------------------------ // partition(): rearrange a into 3 sublists: // - a sublist a[left] ... a[j-1] of values at most a[j] // - a sublist a[j], and // - a sublist a[j+1] ... a[right] of values at least a[j] //------------------------------------------------------ int pivot = a[left].getYear(); int i = left - 1; int j = right + 1; do { do { j-- ; } while (a[j].getYear() > pivot); do { i++ ; } while (a[i].getYear() < pivot); if (i < j) exchange(a[i], a[j]); } while (i < j); return j; } void quickSortYear(vector<Movie> &a) { //------------------------------------------------------ // driver subprogram to sort an entire vector into // ascending order with quickSort. //------------------------------------------------------ quickSortYear(a, 0, a.size()-1); } //---------------------------------------------------------------------------- // void quickSortYear(vector<Movie> &a, int left, int right) { //------------------------------------------------------ // quickSort(): a recursive partitioning-based sort //------------------------------------------------------ if (left < right) { int k = partitionYear(a, left, right); quickSortYear(a, left, k); quickSortYear(a, k+1, right); } }

This post has been edited by **ipushmycar**: 20 February 2011 - 02:27 PM