if(right - left <= 1){//if left and right are right beside eachother, bypass all the swaps if( (Books[m]-> getISBN() ) < (Books[left]-> getISBN()) ) swap(Books, left, m); if( (Books[right]-> getISBN() ) < (Books[left]-> getISBN()) ) swap(Books, left, right); if( (Books[right]-> getISBN()) < (Books[m]-> getISBN()) ) swap(Books, m, right); swap(Books, m, right-1); }else return (Books[right] -> getISBN());//just return the right most element return (Books[right - 1]-> getISBN());