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
Q. Illustrate Diffrent types of modems? There are four different types of modems: half-duplex, full-duplex, synchronous, and asynchronous.With half-duplex modems data can be tr

#question.write cycle timing diagram for maximum mode of 8086 microprocessor.


State about the machine language programs The computer can run only machine language programs, one needs to translate above programs to machine language programs. To translate

Your professor wants you to fill a two-dimensional N by N matrix with some numbers by following a specific pattern. According to his explanation as in the figure below, you have to

Q. Collective Communications? A number of message-passing systems allow communication involving more than two processors. Such type of communication can be known as collective

The search method for searching a sorted file that needs increased amount of space is The search technique for searching a sorted file that needs increased amount of space

Specifying Optimisation Criteria Specify values to be minimized, maximized or optimized. You can understand it as way you normalize data in database. For instance, you should

What are the different sections of a report? A report is categorized into many sections: The Report header: In this you place a control which must appear only at the startin

State about the Data Glove  Data glove is used to grasp a "virtual" object. The glove is constructed with a series of sensors that detect hand and finger motions. Electromagnet