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
Register Transfer Micro-operations These micro-operations as the name proposes transfer information from one register to another. The information doesn't change during these mi

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Forward Chaining - Artificial intelligence: Imagine we have a set of axioms which we know are true statements regarding the world. If we set these to each be a starting state o

This is an embedded system that involves the integration of hardware and software design stages. It consists of the user interface (keypads and LCD display) and two Peripheral Inte

I need help to create test cases for the MIPS Instruction set architecture

Units of artificial neural networks: However the input units simply output the value that was input to them from the example to be propagated. So every other unit in a network

Two properties of recursion are:- 1. A smallest, base case that is processed without recursion and acts as decision criterion for stopping the method of computation and 2.

Format functions can be used to format lot of the expressions such as money, time, date, percentages and numbers. These functions are much easier to use in VBA. User defined date,

Multiplication Algorithms Multiplication of the two fixed-point binary numbers in signed magnitude representation is done with paper and pencil through a process of successive

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec