Sorting, Computer Engineering

Different sorting algorithm will be discussed in the lecutres. The task in this worksheet is to write a funtions based on the Quicksort algorithm.

When sorting an array of objects some objects might swap places. This can by very expensive in terms of time and space, as each swap requires to copy an object. We have seen in the previous part of the module that this could potential be computationally expensive (deep copy).
The function that you should implement takes an array of a template class as pass-by-reference. Instead of sorting this array it returns a new array of int. In this new array the first number is the index of the smallest object in the original array, the next number is the index of the 2nd smallest object in the original array and so on.
Example, for parameter ["michael", "sam", "chris", "tom", "anna", "nick"]
the function should return [4, 2, 0, 5, 1, 3]

The function declaration is

        template int * index(const T & array,int size)

Your function should be based on the quicksort algorithm. The given array of objects should not be altered. Hint: You might want to consider to write an additional function that can be recursively called.
A test program is provided . To compile the program you can use






using namespace std;

int main() {

   int size = 10;

   int *data=new int[size];

   for(int i=0;i < size;i++)

      data[i]=rand()% 1000;

   cout << endl<<"unsorted"<


   for(int i=0;i


   int * indexA = index(data,size);


   for(int i=0;i


   cout << endl;

   for(int i=0;i


   cout << endl;

   delete [] data;

   delete [] indexA;

  return 0;


Posted Date: 2/25/2013 4:12:04 AM | Location : United States

Related Discussions:- Sorting, Assignment Help, Ask Question on Sorting, Get Answer, Expert's Help, Sorting Discussions

Write discussion on Sorting
Your posts are moderated
Related Questions
What is data hazard? Any condition that causes the pipeline to stall is known as a hazard. A data hazard is any condition in which either the source or destination operands of

What are the registers generally contained in the processor? MAR-memory address register MDR-memory data register IR-Instruction Register RO-Rn-General purpose registe

Q. What is a DSS and Describe its components? A decision support system (DSS) is a highly flexible and interactive IT system that is designed to support decision making when t

Voice synthesis Loud speakers and special software are used to output information in the form of sound to help blind and partially-sighted people; it also helps people who have d

Explain the working of Dynamic RAM? A plain piece of hardware called a DRAM controller can be used to make DRAM behave more like SRAM and the job of the DRAM controller is to p

Q. What is a breeder reactor? 92 U 238 and 90 Th 232 aren't fissile materials but are abundant in nature. In the reactor these are able to be converted into a fissile mater

design modulo 12 up synchronous counter using t flip flop

What is concurrent control? Control resides concurrently in various independent objects, every a separate task. A task can wait for input but other task continues implementatio

Coupling and cohesion can be shown using a:- Dependence matrix

What is meant by a field The consecutive nonwhite space characters that define a data item collectively define a field. It is possible  to limit the number of such characters b