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 violating basic security principles, Explain the violating basi...

Explain the violating basic security principles There are drawbacks to permitting users to access the Intranet as well as not permitting them. A simple consideration such as a

Main benefits of cd-rom, The main benefits of CD-ROMs are: These are...

The main benefits of CD-ROMs are: These are removable disks, thus they are suitable for archival storage mass replication is cheap and fast large storage capacity

Determine the advantages of sixth generation computers, Determine the advan...

Determine the advantages of sixth generation computers One of the major dramatic changes in sixth generation will be the explosive growth of wide area networking. Network bandw

Alignment with your indents, Use Microsoft SQLServer to make the following ...

Use Microsoft SQLServer to make the following queries.  You should also download the Pirate Sports DM-DD that gives the fields for every table.  Be sure to use proper alignment wit

What are the components of loadrunner, The workings of LoadRunner are The V...

The workings of LoadRunner are The Virtual User Generator, Controller, and the Agent process, LoadRunner examines and Monitoring, LoadRunner Books Online. What Component of LoadRun

Dbms, Find a 3NF decomposition of the following relation scheme: University...

Find a 3NF decomposition of the following relation scheme: University (Faculty, Dean, Department, Chair, Professor, Rank, Student}. The University relation satisfies the following

Reference table and a reference field, A field containing currency amounts ...

A field containing currency amounts (data type CURR) must be assigned to a reference table and a reference field. Explain. As a reference table, a system having all the valid

Dbms, aggregation in dbms?

aggregation in dbms?

Explain classless inter-domain routing, Explain Classless Inter-Domain Rout...

Explain Classless Inter-Domain Routing. It is a new addressing scheme for the internet that permits for more efficient allocation of IP addresses than old class A, B and C addr

Associative array processing, Associative Array Processing Consider tha...

Associative Array Processing Consider that a list of record or a table is stored in the memory and you want to search some information in that list. For example, the list havin

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