Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the quick sort implementation in the textbook to sort the array using pivot as the median of the first, last, and middle elements of

Modify the quick sort implementation in the textbook to sort the array using pivot as the median of the first, last, and middle elements of the array. Add the modified quick sort implementation to the arrayListType class provided (arrayListType.h). Ask the user to enter a list of positive integers ending with -999, sort the integers, and display the pivots for each iteration and the sorted array.
Here is the provided arrayListType.h file. Please also explain where the codes should be as well(whether its in the .h or the .cpp and explain why):
the last bit of code from the last page(also the same bit cut off at the end of page 5) is here:
template
void arrayListType::remove(const elemType& removeItem)
{
int loc;
if (length ==0)
cerr "Cannot delete from an empty list." endl;
else
{
loc = seqSearch(removeItem);
if (loc !=-1)//the item to be removed
removeAt(loc); //exists in the list
else
cout "The item to be deleted is not in the list."
endl;
}
}//end remove
template
arrayListType::arrayListType(int size)
{
if (size 0)
{
cerr "The array size must be positive. Creating "
"an array of size 100." endl;
maxSize =100;
}
else
maxSize = size;
length =0;
list = new elemType[maxSize];
//assert(list != NULL);
}
template
arrayListType::~arrayListType()
{
delete[] list;
}
template
arrayListType::arrayListType
(const arrayListType& otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;
list = new elemType[maxSize]; //create the array
assert(list != NULL); //terminate if unable to allocate
//memory space
for (int j =0; j length; j++)//copy otherList
list[j]= otherList.list[j];
}//end copy constructor
template
const arrayListType& arrayListType::operator=
(const arrayListType& otherList)
{
if (this != &otherList)//avoid self-assignment
{
delete[] list;
maxSize = otherList.maxSize;
length = otherList.length;
list = new elemType[maxSize]; //create the array
assert(list != NULL); //if unable to allocate memory
//space, terminate the program
for (int i =0; i length; i++)
list[i]= otherList.list[i];
}
return *this;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

What is the meaning and definition of E-Business?

Answered: 1 week ago

Question

Identify five strategies to prevent workplace bullying.

Answered: 1 week ago