Lab #4 Templates Solution

$30.00

Description

### Guidelines

This is an individual lab assignment. You must do the vast majority of the work on your own. It is permissible to consult with classmates to ask general questions about the assignment, to help discover and fix specific bugs, and to talk about high level approaches in general terms. It is not permissible to give or receive answers or solution details from fellow students.

You may research online for additional resources; however, you may not use code that was written specifically *to* solve the problem you have been given, and you may not have anyone else help you write the code or solve the problem. You may use code snippets found online, providing that they are appropriately and clearly cited, within your submitted code.

*By submitting this assignment, you agree that you have followed the above guidelines regarding collaboration and research.*

***

The goal of Lab 4 is to get you to Templatize your code, and use your expanding library for another ADT. You are going to expand and refine your existing library by templatizing your Linked List using C++ templates. Once you have successfully templated your code, you will use your fancy new template list library to implement a Queue data structure.

:bulb: You do not have to keep your LinkList the same as the project. You can start fresh if you like.

#### (Parts A must be completed in lab)

## Part A: Creating a Template Class

As you are templatizing your Linked List, be sure to remember the following:

* All of your code must be moved into the header file. You will need to eliminate the .cpp file completely.

* Your linked list will also need the following public interface:

* LinkedList()

* LinkedList(const LinkedList<type> & sll)

* void insert(<type> data);

* inserts a copy of the data into the list

* <type>& read();

* returns a reference to the next item in the list and advances an internal iterator to the next element

* bool empty();

* returns true the the list is empty

* bool remove(<type> &data);

* removes the comparable value (operator==) from the list

* Dont worry if there are multiple items of the same value. Juts remove the first one you come across.

* You may add any additional methods you require. This means you can use your existing methods to implement the above interface if you want to.

* :bulb: Every instance of ‘Ant’ from your previous code needs to become a type variable, and no specific calls to Ant methods should remain.

* Here is a resource that gives a brief overview of templates if you need a syntax reminder

* https://www.tutorialspoint.com/cplusplus/cpp_templates.htm

## Part B: Using your Linked List Library for a Queue

Once you have completed your templated linked list, you will use it to create Queue template data structure. Your Queue should be in separate file (Queue.h), and should use your Linked List as an internal data structure. This means you need to have the following methods:

* enqueue(<type> data)

* Adds a data object onto the queue and returns a boolean if successful

* dequeue()

* removes a data object from the queue and returns it

* peek()

* returns a copy (not a reference) of the data object but does not remove it from the list

* empty()

* returns a boolean, true if the queue is empty, false if it contains 1 or more elements

* clear()

* deletes all items from the queue

HINT: It can make things much easier is you make Queue a friend class of your LinkedList, but don’t forget that Queue is a template.

## Part C : Code Organization and Submission

* Required code organization:

* lab4.cpp (driver code – You must include this file in your submission)

* LinkedList.h

* Queue.h

* makefile

* executable should be called: lab4

* You should have all the same labels in your makefile from the previous assignments

Below is just a reminder of the commands you should use to submit your code. If you cannot remember the exact process, please review lab 1.

*These commands all presume that your current working directory is within the directory tracked by `git`.*

“`git

git add LinkedList.h

git commit -a -m “first commit”

git push

“`

Lastly we are going to make our final commit. You will need to do this when your submission is ready for grading.

“`shell

git commit –allow-empty -m “final commit”

git push

“`

:warning: Remember, you __MUST__ make a submission with the comment “final commit” before the deadline to be considered on time.