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
What is an expression tree? How an expression is evaluated using an expression tree? Algebraic expressions is as given here a/b+(c-d)e That has an inherent tree-like structure

What is a Daemon? A daemon is a method that detaches itself from the terminal and runs, disconnected, in the background, waiting for requests and responding to them. It can als

The most common type of non-volatile memory is the ROM device. This device is read only and the data is masked into the chip during manufacture. Variations of the ROM are one off p

what is system programming? System programming is the activity of implementing and designing SPs. System programs that are the standard component of the s/w of most computer

What is the fundamental difference between the transactions made using Smart Card and E-cash? Smart Card and E-Cash: E-cash storable smart cards can dispense and store ca

Illustrate about the Problem statement Problem statement would not be incomplete, inconsistent and ambiguous. Try to state the requirements precisely and point to point. Do no

Explain the term- Tracker ball and Braille printers Tracker ball Easier to use than a mouse if people have problems using their arms and hands or if they have a coordinati

In computing, virtual memory is a memory management method developed for multitasking kernels. This technique virtualizes computer architecture's various forms of computer data sto

WestEast College hires you as a systems analyst to design its new admission/registration system. WestEast College is one of the top ranked schools in the United States. It is a

What is phase encoding or Manchestor encoding?  It is the method for combining clock information with data. It is a scheme in which alters in magnetization occur for each data