Sorting, Computer Engineering

Assignment Help:

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;

}


Related Discussions:- Sorting

Explain the working of master-slave JK flip flop, With relevant diagram exp...

With relevant diagram explain the working of master-slave JK flip flop. Ans. Master-Slave J-K FLIP-FLOP: A cascade of two S-R FLIP-FLOPS is a master-slave J-K FLIP-FLOP. One

Simplify the expressions using boolean postulates, Simplify the given expre...

Simplify the given expressions using Boolean postulates XY + X‾Z‾  + XY‾Z (XY + Z) Ans. XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾ + XY‾Z (XY + Z) = XY + X‾Z‾  + XXYY‾Z

Largest and the second largest number, The largest and the second largest n...

The largest and the second largest number from a set of n distinct numbers can be found in    O (n)

What is cache memory, What is cache memory? The small and fast RAM unit...

What is cache memory? The small and fast RAM units are known as caches. When the implementation of an instruction calls for data located in main memory, the data are obtained a

What is the ccitt standard bandwidth for speech, The CCITT standard bandwid...

The CCITT standard bandwidth for speech is: (A) 20000 Hz                                  (B) 15000 Hz (C) 7000 Hz                                    (D) 3400 Hz Ans:

What do you mean by shopping bots, Q. What do you mean by shopping bots? ...

Q. What do you mean by shopping bots? ANSWER: A shopping bot or buyer agent is an intelligent agent on a Web site that assists you, the customer, search the products and servic

Advantages of random scan display, Advantages of random scan display ...

Advantages of random scan display Early computer displays: basically an oscilloscope. Control X, Y with vertical/horizontal plate voltage. Often used intensity as

How are standard query operators implemented in linq, Standard Query Operat...

Standard Query Operators are executed as extension methods in .NET Framework. These Standard Query Operators can be used to work with any collection of objects that executes the IE

Critical path analysis, Given the information provided in Table 1: ...

Given the information provided in Table 1: Prepare an Activity on the Node (AON) Network Diagram ( I recommend you  use MS Project or any drawing tool); Prepare

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd