Question: Project Objective: in completing this project, you will ? Enhance your ability on coding sorting algorithms ? Understand the effect of big O( ) notation

Project Objective: in completing this project, you will

? Enhance your ability on coding sorting algorithms ? Understand the effect of big O( ) notation on different sorting algorithm in detail You need to implement the following sorting algorithms: (1) Insertion Sort (O(N^2)) (2) Heap Sort (O(NlogN)) (3) Merge Sort (O(NlogN)) (4) Quick Sort (O(NlogN)) (5) Counting Sort or Radix Sort (O(N))

My insert code:

template void insertionSort( vector & a )

{

for( int p = 1; p < a.size( ); p++ )

{

Comparable tmp = a[ p ];

int j;

for( j = p; j > 0 && tmp < a[ j - 1 ]; j-- )

a[ j ] = a[ j - 1 ];

a[ j ] = tmp;

}

}

And this is my code for the quicksort split and declaring the pivot.

int split (ElementType x[], int first, int last)

{

ElementType pivot = x[first];

int left = first, right = last;

While (left < right)

{

while (pivot < x[right])

right--;

while (left < right && x[left]<=pivot)

left++;

if (left < right)

swap(x[left,x[right]])

}

int pos = right;

x[first] = x[pos];

x[pos] = pivot;

return pos;

}

Any help would be greatly appreciated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!