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 real time process control, Explain the Real time process contro...

Explain the Real time process control Process control is a real time system. Though this is very different to real time (transaction) processing; this system generally involves

What are transmission bridges, What are transmission bridges? A usual ...

What are transmission bridges? A usual transmission bridge is demonstrated in figure. The series capacitance and the shunt inductances of the two relays give a high-pass filte

Rectifier output with fitters, Rectifier output with fitters: When hal...

Rectifier output with fitters: When half-wave and full-wave rectification suffice to deliver a type of DC output, neither produces constant-voltage DC (direct current). To gen

Electronic brokerage facilitate search and retrieval, How does electronic b...

How does electronic brokerage facilitate search and retrieval of information? E Brokerage facilitates search and retrieval of Information: The success aspect of a brokera

How is a property designated as read-only, How is a property designated as ...

How is a property designated as read-only?  In VB.NET: Public Read-Only Property Property Name As Return Type Get? Your Property execution goes in here End Get End Property.

Give detail explanation about arithmetic micro-operations, Give detail expl...

Give detail explanation about Arithmetic Micro-operations These micro-operations perform some essential arithmetic operations on numeric data stored in the registers. These bas

Pci bus transactions - computer architecture, PCI bus transactions: PC...

PCI bus transactions: PCI bus traffic is prepared of a series of PCI bus transactions. Each transaction is build up of an address phase that is followed by 1 or more data phas

Define the state and instance of properties of object, Define the state and...

Define the state and instance of properties of object A state encompasses all properties of object along with values of each of these properties. An instance is a concr

Explain working of intranet, Intranets are mainly "small" Internets. They u...

Intranets are mainly "small" Internets. They use same network facilities that Internet does, though access is restricted to a limited sphere. For example, a company can set up an i

What is reification, What is reification? It is the promotion of someth...

What is reification? It is the promotion of something that is not an object into an object. Helpful method for Meta applications. It shifts the level of abstraction. Promote

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