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. Main Function #include #include "arrayListType.h" using namespace std; int main() {  arrayListType list; int num; cout << "Line 8: Enter numbers ending with -999" << endl; cin >> num; while (num != -999) { list.insert(num); cin >> num; } cout << "Line 15: The list before sorting:" << endl; list.print(); cout << endl; list.selectionSort(); cout << "Line 19: The list after sorting:" << endl; list.print(); cout << endl; return 0; }   Header File (arrayList.h) Including images #include #include   using namespace std; #ifndef H_arrayListType #define H_arrayListType template class arrayListType { public:     const arrayListType& operator=         (const arrayListType&);         bool isEmpty() const;     bool isFull() const;     int listSize() const;     int maxListSize() const;     void print() const;     bool isItemAtEqual(int location, const elemType& item) const;          void insertAt(int location, const elemType& insertItem);         void insertEnd(const elemType& insertItem);         void removeAt(int location);          void retrieveAt(int location, elemType& retItem) const;          void replaceAt(int location, const elemType& repItem);          void clearList();          int seqSearch(const elemType& item) const;          void insert(const elemType& insertItem);          void remove(const elemType& removeItem);          arrayListType(int size = 100);          arrayListType(const arrayListType& otherList);          ~arrayListType();      protected:     elemType* list;     int length;     int maxSize; }; #endif template bool arrayListType::isEmpty() const {     return (length == 0); } template bool arrayListType::isFull() const {     return (length == maxSize); } template int arrayListType::listSize() const {     return length; } template int arrayListType::maxListSize() const {     return maxSize; } template void arrayListType::print() const {     for (int i = 0; i < length; i++)         cout << list[i] << " ";     cout << endl; } template bool arrayListType::isItemAtEqual (int location, const elemType& item) const {     return(list[location] == item); } template void arrayListType::insertAt (int location, const elemType& insertItem) {     if (location < 0 || location >= maxSize)         cerr << "The position of the item to be inserted "         << "is out of range" << endl;     else         if (length >= maxSize)             cerr << "Cannot insert in a full list" << endl;         else         {             for (int i = length; i > location; i--)                 list[i] = list[i - 1];             list[location] = insertItem;             length++;         } } template void arrayListType::insertEnd(const elemType& insertItem) {     if (length >= maxSize)         cerr << "Cannot insert in a full list" << endl;     else     {         list[length] = insertItem;         length++;     } } template void arrayListType::removeAt(int location) {     if (location < 0 || location >= length)         cerr << "The location of the item to be removed "         << "is out of range" << endl;     else     {         for (int i = location; i < length - 1; i++)             list[i] = list[i + 1];         length--;     } } template void arrayListType::retrieveAt (int location, elemType& retItem) const {     if (location < 0 || location >= length)         cerr << "The location of the item to be retrieved is "         << "out of range." << endl;     else         retItem = list[location]; } template void arrayListType::replaceAt (int location, const elemType& repItem) {     if (location < 0 || location >= length)         cerr << "The location of the item to be replaced is "         << "out of range." << endl;     else         list[location] = repItem; } template void arrayListType::clearList() {     length = 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Main Function

#include <iostream>
#include "arrayListType.h"
using namespace std;


int main()

arrayListType<int> list;
int num;
cout << "Line 8: Enter numbers ending with -999" << endl;
cin >> num;


while (num != -999)
{
list.insert(num);
cin >> num;
}


cout << "Line 15: The list before sorting:" << endl;
list.print();
cout << endl;


list.selectionSort();
cout << "Line 19: The list after sorting:" << endl;
list.print();
cout << endl;


return 0;
}

 

Header File (arrayList.h) Including images

#include <iostream>
#include <cassert> 

using namespace std;

#ifndef H_arrayListType
#define H_arrayListType

template <class elemType>
class arrayListType
{
public:
    const arrayListType<elemType>& operator=
        (const arrayListType<elemType>&);    

    bool isEmpty() const;

    bool isFull() const;

    int listSize() const;

    int maxListSize() const;

    void print() const;

    bool isItemAtEqual(int location, const elemType& item) const;
    
    void insertAt(int location, const elemType& insertItem);
   
    void insertEnd(const elemType& insertItem);
   
    void removeAt(int location);
    
    void retrieveAt(int location, elemType& retItem) const;
    
    void replaceAt(int location, const elemType& repItem);
    
    void clearList();
    
    int seqSearch(const elemType& item) const;
    
    void insert(const elemType& insertItem);
    
    void remove(const elemType& removeItem);
    
    arrayListType(int size = 100);
    
    arrayListType(const arrayListType<elemType>& otherList);
    
    ~arrayListType();
    
protected:
    elemType* list;
    int length;
    int maxSize;
};
#endif

template <class elemType>
bool arrayListType<elemType>::isEmpty() const
{
    return (length == 0);
}


template <class elemType>
bool arrayListType<elemType>::isFull() const
{
    return (length == maxSize);
}

template <class elemType>
int arrayListType<elemType>::listSize() const
{
    return length;
}


template <class elemType>
int arrayListType<elemType>::maxListSize() const
{
    return maxSize;
}

template <class elemType>
void arrayListType<elemType>::print() const
{
    for (int i = 0; i < length; i++)
        cout << list[i] << " ";
    cout << endl;
}

template <class elemType>
bool arrayListType<elemType>::isItemAtEqual
(int location, const elemType& item) const
{
    return(list[location] == item);
}

template <class elemType>
void arrayListType<elemType>::insertAt
(int location, const elemType& insertItem)
{
    if (location < 0 || location >= maxSize)
        cerr << "The position of the item to be inserted "
        << "is out of range" << endl;
    else
        if (length >= maxSize)
            cerr << "Cannot insert in a full list" << endl;
        else
        {
            for (int i = length; i > location; i--)
                list[i] = list[i - 1];
            list[location] = insertItem;

            length++;
        }
}

template <class elemType>
void arrayListType<elemType>::insertEnd(const elemType& insertItem)
{
    if (length >= maxSize)
        cerr << "Cannot insert in a full list" << endl;
    else
    {
        list[length] = insertItem;
        length++;
    }
}

template <class elemType>
void arrayListType<elemType>::removeAt(int location)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be removed "
        << "is out of range" << endl;
    else
    {
        for (int i = location; i < length - 1; i++)
            list[i] = list[i + 1];
        length--;
    }
}

template <class elemType>
void arrayListType<elemType>::retrieveAt
(int location, elemType& retItem) const
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be retrieved is "
        << "out of range." << endl;
    else
        retItem = list[location];
}

template <class elemType>
void arrayListType<elemType>::replaceAt
(int location, const elemType& repItem)
{
    if (location < 0 || location >= length)
        cerr << "The location of the item to be replaced is "
        << "out of range." << endl;
    else
        list[location] = repItem;
}

template <class elemType>
void arrayListType<elemType>::clearList()
{
    length = 0;
}

File Edit View Git Project Build Debug Test Analyze
292 2.5.
Miscellaneous Files
227
228
229
230
231
231
232
252
233
233
234
235
293
236
250
237
238
258
239
239
240
240
241
241
242
Ste
243
42
244
A
245
245
246
240
258
200
259
260
261
262
eve
263
200
264
201
265
200
266
200
267
200
268
200
269
200
270
271
272
273
224
274
275
276
276
277
277
278
279
280
100 %
template <class elemType>
BarrayListType<elem Type>:: arrayListType(int size)
247
247
248
249
250
template <class elemType>
251 arrayListType<elemType>:: arrayListType
252
(const arrayListType<elem Type>& otherList)
253
254
255
256
257
200
{
@
if (size < 0)
{
{
maxSize = 100;
cerr << "The array size must be positive. Creating "
<< "an array of size 100. " << endl;
else
maxSize = size;
length = 0;
list = new elemType [maxSize];
template <class elemType>
BarrayListType<elem Type>::~arrayListType()
delete[] list;
maxSize = otherList.maxSize;
length = otherList.length;
list = new elemType [maxSize];
assert (list != NULL);
for (int j = 0; j < length; j++)
list[j] = otherList.list[j];
|{
81 if (this != &otherList)
template <class elemType>
const arrayListType<elem Type>& arrayListType<elemType>::operator=
(const arrayListType<elem Type>& otherList)
delete[] list;
maxSize = otherList.maxSize;
length = otherList.length;
list = new elemType [maxSize];
assert (list != NULL);
for (int i = 0; i < length; i++)
list[i] = otherList.list[i];
Tools Extensions
return *this;
▶ Attach...
No issues found
@
Window Help Search (Ctrl+Q)
(Global Scope)
€2 ■111
P
Solution1
▶
Ln: 1 Ch: 1 SPC
+ Tabs
CRLF
Sign in &
Live Share
Miscellaneous Files
arrayList Type(no comments).h
Transcribed Image Text:File Edit View Git Project Build Debug Test Analyze 292 2.5. Miscellaneous Files 227 228 229 230 231 231 232 252 233 233 234 235 293 236 250 237 238 258 239 239 240 240 241 241 242 Ste 243 42 244 A 245 245 246 240 258 200 259 260 261 262 eve 263 200 264 201 265 200 266 200 267 200 268 200 269 200 270 271 272 273 224 274 275 276 276 277 277 278 279 280 100 % template <class elemType> BarrayListType<elem Type>:: arrayListType(int size) 247 247 248 249 250 template <class elemType> 251 arrayListType<elemType>:: arrayListType 252 (const arrayListType<elem Type>& otherList) 253 254 255 256 257 200 { @ if (size < 0) { { maxSize = 100; cerr << "The array size must be positive. Creating " << "an array of size 100. " << endl; else maxSize = size; length = 0; list = new elemType [maxSize]; template <class elemType> BarrayListType<elem Type>::~arrayListType() delete[] list; maxSize = otherList.maxSize; length = otherList.length; list = new elemType [maxSize]; assert (list != NULL); for (int j = 0; j < length; j++) list[j] = otherList.list[j]; |{ 81 if (this != &otherList) template <class elemType> const arrayListType<elem Type>& arrayListType<elemType>::operator= (const arrayListType<elem Type>& otherList) delete[] list; maxSize = otherList.maxSize; length = otherList.length; list = new elemType [maxSize]; assert (list != NULL); for (int i = 0; i < length; i++) list[i] = otherList.list[i]; Tools Extensions return *this; ▶ Attach... No issues found @ Window Help Search (Ctrl+Q) (Global Scope) €2 ■111 P Solution1 ▶ Ln: 1 Ch: 1 SPC + Tabs CRLF Sign in & Live Share Miscellaneous Files arrayList Type(no comments).h
File Edit View Git Project Build Debug
177
77
178
1/0
Miscellaneous Files
173
174
template <class elemType>
175 int arrayListType<elemType>::seqSearch(const elemType& item) const
176
176
{
179
179
180
100
181
101
182
102
183
103
184
104
185
185
186
100
187
107
188
100
189
109
190
200
191
191
192
192
193
193
194
195
196
197
198
200
199
200
201
201
202
eve
203
204
205
206
207
208
209
210
211
212
213
***
214
215
216
247
217
218
219
220
221
222
222
223
225
224
225
226
227
228
100 %
292
int loc;
bool found = false;
for (loc = 0; loc < length; loc++)
if (list[loc] == item)
if (found)
return loc;
else
found = true;
break;
return -1;
template <class elemType>
void arrayListType<elemType>::insert(const elemType& insertItem)
{
int loc;
if (length == 0)
list[length++] = insertItem;
else
else if (length == maxSize)
cerr << "Cannot insert in a full list." << endl;
loc = seqSearch(insertItem);
if (loc == -1)
else
list[length++] = insertItem;
cerr << "the item to be inserted is already in "
<< "the list. No duplicates are allowed." << endl;
template<class elemType>
Test Analyze Tools Extensions Window
▶ Attach...
else
void arrayListType<elem Type>::remove(const elemType& removeItem)
int loc;
if (length == 0)
cerr << "Cannot delete from an empty list." << endl;
loc seqSearch(removeItem);
if (loc != -1)
removeAt (loc);
else
cout << "The item to be deleted is not in the list."
<< endl;
No issues found
Help Search (Ctrl+Q)
(Global Scope)
€2 ■111
P
Solution1
▶ Ln: 1 Ch: 1 SPC
+ Tabs
CRLF
Sign in &
Live Share
Miscellaneous Files
arrayList Type(no comments).h
Transcribed Image Text:File Edit View Git Project Build Debug 177 77 178 1/0 Miscellaneous Files 173 174 template <class elemType> 175 int arrayListType<elemType>::seqSearch(const elemType& item) const 176 176 { 179 179 180 100 181 101 182 102 183 103 184 104 185 185 186 100 187 107 188 100 189 109 190 200 191 191 192 192 193 193 194 195 196 197 198 200 199 200 201 201 202 eve 203 204 205 206 207 208 209 210 211 212 213 *** 214 215 216 247 217 218 219 220 221 222 222 223 225 224 225 226 227 228 100 % 292 int loc; bool found = false; for (loc = 0; loc < length; loc++) if (list[loc] == item) if (found) return loc; else found = true; break; return -1; template <class elemType> void arrayListType<elemType>::insert(const elemType& insertItem) { int loc; if (length == 0) list[length++] = insertItem; else else if (length == maxSize) cerr << "Cannot insert in a full list." << endl; loc = seqSearch(insertItem); if (loc == -1) else list[length++] = insertItem; cerr << "the item to be inserted is already in " << "the list. No duplicates are allowed." << endl; template<class elemType> Test Analyze Tools Extensions Window ▶ Attach... else void arrayListType<elem Type>::remove(const elemType& removeItem) int loc; if (length == 0) cerr << "Cannot delete from an empty list." << endl; loc seqSearch(removeItem); if (loc != -1) removeAt (loc); else cout << "The item to be deleted is not in the list." << endl; No issues found Help Search (Ctrl+Q) (Global Scope) €2 ■111 P Solution1 ▶ Ln: 1 Ch: 1 SPC + Tabs CRLF Sign in & Live Share Miscellaneous Files arrayList Type(no comments).h
Expert Solution
steps

Step by step

Solved in 5 steps with 7 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education