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
Network for Digital Methods in the Arts and Humanities: Europe has seen a signifi cant investment in the digitisation of its cultural heritage as part of the worldwide establi

What are the different phases of consumer mercantile model? There are three different phase of consumer mercantile model like listed as in below: • Pre-purchase interaction

Describe the role of Software developers Software developers have wide experience of tackling such issues. Students who develop software project spending days and nights strug

Q. Describe the instruction set architecture? The significant role of the Central Processing Unit (CPU) is to perform calculations, to coordinate all other hardware components,

A sorting algorithm is stable if  Preserves the original order of records with equivalent keys.

HOW TO SAVE YOUR FILE? Step 1: Click on FILE Step 2: Click on SAVE Step 3: Choose the folder in which you want to save Step 4: Provide a name to the file (with .htm /

Q. Show the developments that happened in third generation? The main developments that happened in third generation can be summarized as below: Application of IC circuit

What are the different modes in that 8255 Programmable Peripheral Interface (PPI) can operate?  24 I/O lines in 3-8-bit port groups - A, B, C A, B can be 8-bit input

Explain CSMsgInterface() Function with Predefined Protocol  A REQUEST structure is created for each message sent to the server. Messages passed to CSMsgInterface() as *dataMSG

Q. Illustration of equivalent EXE program? An illustration of equivalent EXE program for COM program is: ; ABSTRACT this program adds 2 8-bit numbers in the memory locations