|
CSC 2200
Fall 2002
Up
| |
Lab preparation (at home)
Goal
Implement a doubly linked list of integers using pointers (NOT arrays) that
supports the following operations:
 | addToFront(): Add a new node at the front of the list |
 | addToEnd(): Add a new node at the end of the list |
 | removeFromFront(): Remove the node from the front of the list |
 | removeFromEnd(): Remove the node from the end of the list |
 | shiftLeft(): Shift the list contents to left. For example, if the list
contains 1, 2, 3, 4, 5, then after invocation of shiftLeft it will contain 2,
3, 4, 5, 1 |
 | shiftRight(): Shift the list contents to right. For example, if the list
contains 1, 2, 3, 4, 5, then after shiftRight is invoked it will contain 5, 1,
2, 3, 4 |
 | print() const: Prints the list contents on the screen |
For your implementation you will need two classes:
struct Node {
int data;
Node * next; // Points to the next node in the list
Node * prev; // Points to the prev node in the list
};
class List {
private:
Node * first; // Points to the first node in the list
Node * last; // Points to the last node in the list
public:
List(); // Initialize the object
~List(); // Destructor
void addToFront(int); // Create a node and add it to the
front of the list
void addToEnd(int); // Create a node and add it to the
end of the list
void removeFromFront(); // Remove a node from the front of the list
void removeFromEnd(); // Remove a node from the end of the list
void shiftLeft(); // Shift the contents of the list to
left by one position
void shiftRight(); // Shift the contents of the list to
right by one position
void print() const;
// Print the contents of the list on the screen
};
Lab report
Finish the implementation and test it.
|