CS 319 Applied Programming Fall 2018 Programming Assignment # 1: Linked Lists, Stacks, Queues
CS 319 Applied Programming Fall 2018 Programming Assignment # 1: Linked Lists, Stacks, Queues
Fall 2018
TAs:
Document conventions: Filenames are given in bold italic. Class names are given in bold type. Code
fragments are given in monospaced font.
The following provides a description of the functions to be implemented for the List class.
List()
~List()
This is the destructor for the doubly linked list. It should delete all nodes in the linked list and deallocate
all dynamically allocated memory.
This function should insert a new node with the value stored in the variable “item”, at the front of the
linked list. Remember to handle any List class variables affected by this operation.
This function should insert a new node with the value stored in the variable “item”, at the rear of the
linked list. Remember to handle any List class variables affected by this operation.
This function should insert a new node with the value stored in the variable “item”, right after the node
that has a value equal to the value of the variable “afterWhat”. If no such node exists in the linked list,
you may insert the new node at the end of the linked list.
Node<T> *GetHead()
This function returns a pointer to the first node in the linked list
Node<T> *GetTail()
This function returns a pointer to the last node in the linked list
Node<T> *SearchFor(T item)
This function searches for a node in the linked list that has value equal to that stored in the variable
“item”. If such a node is found, its address is returned, otherwise, NULL is returned.
This function searches for a node in the linked list that has value equal to that stored in the variable
“item”. If such a node is found, it is deleted from the list. Be sure to update any pointers affected by this
operation.
void DeleteHead()
This function deletes the node at the front of the linked list. Be sure to update any pointers affected by
this operation.
void DeleteTail()
This function deletes the node at the rear of the linked list. Be sure to update any pointers affected by this
operation.
int Length()
This function returns the number of nodes presently in the linked list.
If you encounter any compilation errors, go back to the editor and fix them, then repeat the compilation.
Once the compilation is successful, run the program by issuing the following command from the command
prompt in the same directory:
task1
The output will show which test cases passed and which failed. If all goes well, your output will look like
the following:
The following is a summary of the functions that you must implement for the Stack class:
Stack()
~Stack()
This function is used to add elements to the stack. The elements should be added to the underlying linked
list so that they can be later retrieved efficiently according to the LIFO order.
T Peek()
This function returns the value currently stored at the top of the stack, without actually removing it.
T Pop()
This function removes the element from the top of the stack and returns it.
int Length()
This function returns the number of elements presently on the stack.
Queue()
Queue(Queue<T>& otherQueue)
~Queue()
T Peek()
Return the value of the item stored at the head of the queue without removing it from the queue.
T Dequeue()
Remove the item stored at the head of the queue and return its value.
int Length()
If you encounter any compilation errors, go back to the editor and fix them, then repeat the compilation.
Once the compilation is successful, run the program by issuing the following command from the command
prompt in the same directory:
task2
The output will show which test cases passed and which failed. If all goes well, your output will look like
the following:
Submission instructions
Zip only the source code files and not any object or executable files into one archive. Submit this archive
to slate. The submission must be done before 5 pm on October 29, 2018.