sorting - Quicksort with a twist in c++ -


when sorting array of objects objects might swap places. can expensive in terms of time , space, each swap requires copy object.

in cases sorting entire array not required. example: given array of times marathon. array should sorted fastest 200 times correctly sorted @ start of array. 1 might interested in order of 100 worst times. important here array apart top , buttom not have sorted.

the function should implement not takes pointer array of template class , size of array parameters. takes 2 further parameter front , end . function change given array first front elements smallest in entire array , these front elements sorted. similarly, highest end elements @ end of array , these end elements sorted. other elements don't have sorted.

example, array ["michael", "sam", "chris", "tom", "anna", "nick", "brian", "lisa"] , front =2 , end =3 array after calling function might ["anna", "brian", "michael", "lisa", "chris", "nick", "sam", "tom"] note, important first 2 names "anna" , "brian", array finishes "nick", "sam", "tom"

finally function take 2 further parameters of type int passed reference. when function finishes these contain number of swaps , number method calls during run of function.

the function declaration template < class t> void quicksort(t * array,int size, int front, int end, int & calls, int & swaps) function should based on quicksort algorithm. hence need write addition function contains recursive calls. count number of swaps , calls should use global variables.

can me in this?

sounds homework. rather store entire object array, consider storing pointer object. sort moves pointers. it'll fast.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -