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

Btree, What should the size of ''t'' in btree be depending on the hard disk...

What should the size of ''t'' in btree be depending on the hard disk size

When gravity is the merely force acting on an object, Q. When gravity is th...

Q. When gravity is the merely force acting on an object the object is in what? Answer:- One respond is that it is in free-fall in a vacuum to eliminate atmospheric drag.

Objectives-classification of parallel computers , Objectives After goi...

Objectives After going through this unit, you should be able to: Describe the diffrent criteria on which classification of parallel computers are based; Examine the

Explain the term control dependence, Control Dependence Segments or I...

Control Dependence Segments or Instructions in a program can include control structures. So, dependency among statements is able to be in control structures also. However the

What is metropolitan area network, Q. What is Metropolitan Area Network? ...

Q. What is Metropolitan Area Network? Metropolitan Area Network (MAN):  It is privately or public owned communication system that naturally covers a complete city. Speed is abo

What is co-operative process, What is co-operative process? A process i...

What is co-operative process? A process is co-operating if it can affect or be affected by the other processes implementing in the system. Any process that share data with othe

What is an i/o buffer, What is an I/O buffer? I/O buffer: One ty...

What is an I/O buffer? I/O buffer: One type of input-output requirement arises from devices which have a very high character density as disks and tapes. With these chara

Define public identifiers, Q. Define Public Identifiers? Public Identif...

Q. Define Public Identifiers? Public Identifiers: A public identifier is one which is defined within one module of a program however potentially accessible by all of the other

Find 9''s compliment of bcd number using 4-bit binary adder, Design a circu...

Design a circuit for determining the 9's compliment of a BCD number by using 4-bit binary adder and some external logic gates? Compliment of a BCD number 9's co

SGML, Write short note of SGML

Write short note of SGML

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