Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C++ Here's the Ordered List ADT #include OrderedList.h template OrderedList ::OrderedList ( int maxNumber ) { :List (maxNumber) } template void OrderedList ::insert

Please use C++

image text in transcribed

Here's the Ordered List ADT

#include "OrderedList.h"

template OrderedList::OrderedList ( int maxNumber ) { :List(maxNumber) }

template void OrderedList::insert ( const DataType &newDataItem ) throw ( logic_error ) { if (this ->isFull()) throw logic_error("The list is full ");

if (binarySearch(newDataItem.getKey(), cursor)) dataItems[cursor] = newDataItem;

else { for (int j = size - 1; j > cursor; --j) dataItems[j + 1] = dataitems[j]; ++cursor; ++size; dataItems[cursor] = newDataItem; }

}

template void OrderedList::replace ( const DataType &newDataItem ) throw ( logic_error ) { if (this->isEmpty()) { throw logic_error("listEmpty"); }

if (newDataItem.getKey() == dataItems[cursor].getKey()) { dataItems[cursor] = newDataItem; } else { remove(); insert(newDataItem); }

}

template bool OrderedList::retrieve ( const KeyType& searchKey, DataType &searchDataItem ) { int holdCursor = cursor; bool result = false;

if (binarySearch(searchKey, cursor)) { searchDataItem = dataItems[cursor]; result = true; } else { cursor = holdCursor; result = false; } return result; }

template void OrderedList::merge ( const OrderedList &other ) throw ( logic_error ) { int j = size - 1, k = fromL.size - 1, m = size + fromL.size - 1;

if (size + fromL.size > maxSize) throw logic_error("merged items do not fit within list");

while ((j >= 0) && (k >= 0)) if (fromL.dataItems[k].getKey() == dataItems[j].getKey()) throw logic_error("lists are supposed to have no common keys"); else if (fromL.dataitems[k].getKey() > dataItems[j].getKey()) dataItems[m--] = fromL.dataItems[k--]; else dataItems[m--] = dataItems[j--];

for (m = k; m >= 0; m--) dataItems[m] = fromL.dataItems[m];

size += fromL.size;

if (size != 0) cursor = 0;

}

template bool OrderedList::isSubset ( const OrderedList &other ) { int j = 0, k = 0; bool result = false;

while ((j

if (k == subList.size) result = true;

else result = false;

return result; }

#include "show4.cpp"

Step 1: Create a program that simulates reassembling an incorrectly sequenced message by reading in the packets from a text file, resequencing them, and outputting the original message. Your program should use the Ordered List ADT to assist in reassembling the packet. Each packet in the message file contains a position number and five characters from the message (the packet format shown previously). Ideally, you would base your program on the following declarations. Read each successive packet in the input file into a Packet object and insert the Packet object into the ordered list. Then iterate through the entire list from beginning to end, retrieving each message and printing out the message body. Save your program in packet.cpp

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago