Question: Use C++. Implement an ordered list class implemented as a singly-linked list (not doubly linked) of items arranged in non-descending order. The name of the

Use C++. Implement an ordered list class implemented as a singly-linked list (not doubly linked) of items arranged in non-descending order.

The name of the class is OList. Everything is to be implemented in OList.h rather than using a separate .cpp file.

When an item is inserted in an OList, it is placed in correct position to maintain order.

OList operations include default constructor, copy constructor, constructor that takes an unsorted array parameter, destructor,

print(), printBackwards() (use recursion), getSize(), getSmallest(), removeSmallest() getBiggest() (there is no removeBiggest), operator=(), operator+(), operator+=(), (to merge lists),

operator==(), operator!=(), operator<<() , find(), insert(), remove() , clear(), isEmpty().

(I've left the parentheses empty not because there are always no parameters but to make you figure out the parameter types.)

Note that getSmallest() and getBiggest() might be called on an empty list. In that case the functions should throw a logic_error exception with a suitable message. removeSmallest() will just do nothing on an empty list rather than throw an exception. The required code for the exception is throw logic_error("list is empty");

For the += operation, the items in the other list will be inserted into this list. While not required, think about doing an efficient implementation (O(n) rather than O(n 2)). Note that the testers calls += between a list and itself. Be sure your code works in that situation.

For assignment (operator=) , if the parameter is the current object (e.g myList = myList) your code should output the message "Self assignment ignored." and avoid doing any copying. The output message isn't something we want in a finished version of OList; it's just for testing purposes.

For remove() the default behavior is to remove all occurrences. If a second argument of false is supplied then only the first occurrence is removed. That means you'll need a second parameter with a default value. (There are both types of call in the tester.)

The find() member function should return the index of the first occurrence of the object. Like an array index, 0 will be the index of the first element. If the object is not in the list then find() should return -1. (This function is mostly useful to test whether an item is in the list, but why not return the item's position while we're at it?)

Your class should include three private data members:

a dummy head node which is not a pointer. IMPORTANT: You're required to do it this way, rather than using a head pointer.

a tail pointer to the last node. This time it's a pointer, not a dummy tail node. The motivation for a tail pointer is so that the getBiggest operation is O(1) rather than O(n). Just be aware that it makes the remove() operation less efficient in some cases.

a variable to hold the list's size.

There are no prototypes. You'll need to deduce the from the tester program.

The following private utility function may be useful

// Return a pointer to the Node that val should be inserted after.

// Can also be used by remove() to look for an occurrence of val,

// Also, consider using it for by operator+=.

// pre represents a node where we start the search.

Node * findInsertPoint(Node * pre, const T & val);

For testMemoryLeak your times should meet or beat times in the TesterOutput.

Avoid adding extra functionality to your OList class. If you want to do that, make a separate version for your own use rather than for submission.

Upload only your OList.h and a copy-paste of a sample run using ListTester. cpp. (Make that a . txt file).

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!