Question
Dynamic List Node +i: int +next : Node* -head : Node* +DynamicList() : +~DynamicList() : +clear() : void +insert( i : int) : int +append
Dynamic List | ||
-head : Node* | ||
+DynamicList() : +~DynamicList() : +clear() : void +insert( i : int) : int +append (i : int) : int +remove (i : int) : int +peek(i : int& ) : int +isFull() : bool +isEmpty() : bool +getLength() : int +find(i : int) : int +print() : void
|
Summary
For this assignment, use the above UML diagram to implement a class named DynamicList. DynamicList implements a LinkedList using a pointer-based implementation. You may not use containers from the STL. Your implementation must match the above UML for full credit.
Place the entire class in it's own header file: DynamicList.h. Submit only this file.
I will test your classes by creating a test program that uses the methods for your classes. For full credit, your methods should function as described below.
Attributes
head - A pointer that holds the memory address for the first node of the list.
constructor - sets head to NULL.
destructor - causes all memory to be freed up.
clear() - causes all memory to be freed up.
insert() - inserts the value in parameter i into the list, IN ASCENDING ORDER. Returns 0 if successful, -1 otherwise.
append() - adds the value in parameter i to the end of the list. Returns 0 if successful, -1 otherwise.
remove() - removes the first value found in the list matching the value in parameter i. Returns 0 if successful, -1 otherwise.
isFull() - returns true if the list is full, false otherwise.
isEmpty() - returns true if the list is empty, false otherwise.
find() - returns the relative position of a node containing the value matching the value in parameter i if found in the list, -1 otherwise. ( 0 for the first node, 1 for the second, 2 for the third, ... )
print() - displays the values in the list on a single line, separated by spaces.
peek() - assigns the value at the front of the list to reference parameter i. Returns 0 if successful, -1 otherwise. Does not alter the list in any way.4
getLength() - returns length of list
Feel free to use the attached driver.cpp program to get you started on testing your solution. It is not comprehensive, but can be used as a starting point.
Notes:
insert() and append() would normally not be within the same class, as they have incompatible logic. You are including them both here to avoid writing a second class whose code differs only by one method. When I test your class, insert and append will NOT be invoked on the same object without calling clear first. This way, the object will be tested as an ordered List or an Unordered list.
When could a method fail? For example, insert could fail if the array is full.
Driver Program:
#include "DynamicList.h" #include using namespace std; int main() { DynamicList list; list.append(9); list.append(6); list.append(8); list.print(); list.clear(); list.insert(3); list.insert(5); list.insert(7); list.insert(9); list.print(); list.remove(7); list.remove(6); list.remove(5); list.remove(3); list.remove(9); cout << list.remove(10) << endl; list.print(); return 0; }
*PLEASE ANSWER BY MAKING A HEADER FILE! *
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started