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
how we get a perfect tutorial for face recognition using java

What is a switchboard A switchboard is only a form with command button that open other switchboard or perform tasks like opening forms and printing reports. Switchboard is a t

Write the HTML code for the following table: T E M P E R A T U R E C I T I E S

Q. Illustrate Domain Name System? Domain name is a name which is given to a network for ease of reference. Domain refers to a group of computers which are known by a single com

QWERTY-based keyboards In addition the standard alphabet keys having QWERTY arrangement, a computer keyboard also comprises the control (alt, Del, Ctrl etc. keys) and function

A) Execute a program where an ellipse follows the perimeter of the window. B)  Execute a program that can draw graphs, possibly following your plan from last week. Have it graph

Explain how presentation layer helps in establishing and processing data in End to End layers. The idea of the presentation layer is to stand for information to the communicati

State the data flow diagramming conpects The approach to data flow diagramming is as follows: Create a data flow diagram for each of major outputs of system Work ba

Q. Why we need linker?  The linker: Joins assembled module in one executable program, Produces an .EXE module and initializes with special instructions to facilitate

Q. Describe Memory and Memory unit? Input devices can fetch instructions or data only sequentially though a program may or may not be executed sequentially because looping, jum