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

What is system-software, What is System-software? System-software is co...

What is System-software? System-software is collection of system programs which perform a variety of functions, name are: file editing, IO management, recourse accounting and s

What is ternary association, What is ternary association Associations c...

What is ternary association Associations can be binary, ternary, or have higher order. In use, the vast majority of it is binary or ternary associations. Except a ternary assoc

System software, System Software System software is a group of progr...

System Software System software is a group of programs written to service another programs. Some system software (e.g., compilers editors and file management utilities) proc

List the acid properties, a. List the ACID properties. Describe the usefuln...

a. List the ACID properties. Describe the usefulness of each. b. During its implementation, a transaction passes by several states, until it finally commits or aborts. List all

Networking, how to connect a home network

how to connect a home network

Engineering phyics, what is interference of light explain the nessicity of ...

what is interference of light explain the nessicity of coharent source for obtaining sustain interference pattern

Declare abstract processor arrays, Think about call of two intrinsic functi...

Think about call of two intrinsic functions discussed above for a 32-Processor (4×8) Multicomputer:    The function call NUMBER_OF_PROCESORS () will return 32.

What is interrupt vector table, Interrupt vector table is always created in...

Interrupt vector table is always created in first 1K area of the memory. Explain why? When CPU receives an interrupt type number from PIC, it uses this number to look up corres

What do you mean by data distribution, Q. What do you mean by Data Distribu...

Q. What do you mean by Data Distribution? Data distribution directives tell compiler how program data is to be distributed among memory areas connected with a group of processo

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