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

#include

#include"assessment3.cpp"

#include

#include

#include

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

      cout<

   int * indexA = index(data,size);

   cout<

   for(int i=0;i

      cout<

   cout << endl;

   for(int i=0;i

      cout<

   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
Give the Schematic of Interpretation of HLL program and execution of a machine language program by the CPU. The CPU utilizes a program counter (PC) to notice the address of nex

Multiple Layers of Intranet Security Security requirements vary from organisation to organisation. They also vary on the content that the organisations intend to place on their

Can you define a field without a data element? Yes.  If you require specifying no data element and thus no domain for a field, you can enter data type and field length and a sh

Intel's 8086 was the first 32-bit processor, and as the company had to backward-support the 8086. All the modern Intel-based processors will run in the Enhanced mode, capable of sw

Consider the following instance of the Students relation, sorted by gpa. sid name login age gpa 53831 Madayan madayan@music 11 1.8 53832 Guldu guldu@music 12 2.0 53688 Smith smith

I can send you the lecture notes and assignments, and you will walk me through (either record a screencast, or kind on the assignments in red colored font) steps on how to do the a

Background, Examples and Hypothesis: Now we will switch off with three logic programs. So very firstly, we will have the logic program representing a set of positive examples

Determine the begin - end keywords Group several statements together. Cause the statements to be evaluated sequentially (one at a time) -> Any timing within sequential group

Testing Your Program All programs must be thoroughly tested before they are released to users. Create some sample input files of a small size and manually figure out what the o

Q. What is Gantt chart and Kiviat diagram? Gantt chart: Gantt chart explains numerous activities of every processor with respect to progress in time in busy -overhead - id