CS340 - MP03

The Linked List From Hell

(revised 04SEP2008)

Assignment

This is a two part assignment. In the first part you will implement a linked list class that uses a "generic" data type called elementDataType. In the second part of the assignment, you will use the code created for part one and convert it to a template class. To aid you in this daunting assignment, some header files have been provided below.

Some Header Files

// dataDefinition.h

#ifndef DATADEFINITION_H
#define DATADEFINITION_H

typedef int elementDataType; 

#endif

// List.h

#ifndef LIST_H
#define LIST_H

#include "dataDefinition.h"

struct node {
	elementDataType nodeData;
	node * nodePointer; // self referential
};

class List { // single linked list class
public:
	List() {}; // constructor
	~List() {}; // destructor
	List(const List &) {}; // copy constructor
	void deleteElement(); // deletes the current element
	void addElementAfterCurrent(elementDataType); // adds an element AFTER the current element
	void addElementAsHead(elementDataType);  // adds an element at the list head
	void addElementAsTail(elementDataType);  // adds an element at the list tail
	elementDataType getCurrentElementValue(); // gets data value of current element
	void moveForward(); // move forward one node in list
	bool isFirstElement(); // returns true if current element is list head
	bool isLastElement(); // returns true if current element is head tail
	bool isEmpty(); // returns true if list is empty
	int size(); // returns the size of the list
	void moveToListHead(); // makes current node the list head
	void showList();  // shows list contents - used for debugging
private:
	node * head; // list head
	node * currentNode; // current node being processed
};
#endif

Zipped .NET 2005 projects is available here.

Implementation

For part one, use the header files provided above. Call the project mp03a. The class will be known as List.

For part two, call the project mp03b. The class will be known as TemplateList.

Pre and Post Conditions

When implementing the class, all applicable pre and post conditions must be tested. If a pre or post condition if violated, an error message should be printed to the console. For example if we were to try and remove the current element from an empty List, an error message like "cannot remove an element from an empty list" should be printed.

Test Driver

You must create a test driver that exercises all aspects of your classes (including the copy constructors). That is, each of the methods (as well as their pre/post conditions) must be exercised

Other Requirements

For part 1, use the provided header file and put your implementation of the list in a file called List.cpp.

For part 2, put the header and implementation code in a single file called TemplateList.h.

What You'll Turn In

Your submitted program should adhere to the CS340 coding standards.

Submit a file mp3.zip to the homework web site. The file should contain both projects as well as the source files so that you code may be easily recompiled. Do not include either the Debug or Release directories generated by .NET.