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

Why we use debugger, Q. Why we use Debugger? Debugger is a program whic...

Q. Why we use Debugger? Debugger is a program which allows the user to test as well as debug the object file.  Theuser can use this program to perform subsequent functions.

Which is not a valid page replacement policy, Which is not a valid page rep...

Which is not a valid page replacement policy? Ans. RU policy (Recurrently used) is not a valid page replacement policy.

What is bank interleaving, Interleaved memory is a method for compensating ...

Interleaved memory is a method for compensating the relatively slow speed of DRAM. The CPU can access alternative sections instantly without waiting for memory to be cached. Multip

Evaluate 23 - 48 using the 2's complement method, Perform the 23 - 48 opera...

Perform the 23 - 48 operations using the 2's complement method. Ans. Given 23 - 48 firstly add them       23                         0 1 0 1 1 1 - (- 48)                     +

Overfitted the data, Overfitted the data: Moreover notice that as time...

Overfitted the data: Moreover notice that as time permitting it is worth giving the training algorithm the benefit of the doubt as more as possible. However that is, the error

What are the disadvantages of public key cryptography, What are the disadva...

What are the disadvantages of Public Key Cryptography? Disadvantages of Public Key Cryptography are as given below: a) It is used to encrypt a secret key that is used to e

Opengl, scan line seed fill algorithm program using opengl

scan line seed fill algorithm program using opengl

Why does dma have priority over the cpu, Why does DMA have priority over th...

Why does DMA have priority over the CPU when both request a memory transfer? The data transfer monitored by DMA controller which is called as DMA channel. The CPU is included o

Explain data parallel programming, Q. Explain Data Parallel Programming? ...

Q. Explain Data Parallel Programming? In data parallel programming model major focus is on performing concurrent operations on a data set. The data set is characteristically or

Explain lan topologies, Explain LAN Topologies and its basic topologies. ...

Explain LAN Topologies and its basic topologies. LAN Topologies: Network topology is a physical schematic that shows interconnection of the various users. There are four fund

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