Having trouble with doubly linked list

I am brand new to C++ and I need to make a doubly linked list using 3 classes. I was given the 3 header files for the classes, and I need to create 3 complete .cpp files for each of the classes. I have ListNode.h, List.h, and ListIterator.h. I am having trouble with where to start on the ListIterator and ListNode class. I don't really know how to make the constructors for those classes.

Here is the source code for the header files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef LISTNODE_H
#define LISTNODE_H

// needed because NULL is part of std namespace
#include <iostream>
using namespace std;

class ListNode {
public:
    ListNode();	//Constructor

private:
    int value;
    ListNode *next, *previous;	//for doubly linked lists
    friend class List;	// List needs to be able to access/change
    // ListNode's next and previous pointers
    friend class ListItr;	// ListItr needs to access/change

    // Not writing a destructor is fine in this case since there is no
    // dynamically allocated memory in this class

};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include "ListNode.h"
#include "ListItr.h"
using namespace std;

class ListItr;

class List {
public:
    List();				//Constructor
    List(const List& source);	//Copy Constructor
    ~List();			//Destructor
    List& operator=(const List& source);	//Equals Operator
    bool isEmpty() const;		//Returns true if empty; else false
    void makeEmpty();	//Removes all items except blank head and tail
    ListItr first(); 		//Returns an iterator that points to
    //the ListNode in the first position
    ListItr last();			//Returns an iterator that points to
    //the ListNode in the last position
    void insertAfter(int x, ListItr position);
    //Inserts x after current iterator position p
    void insertBefore(int x, ListItr position);
    //Inserts x before current iterator position p
    void insertAtTail(int x);	//Insert x at tail of list
    void remove(int x);		//Removes the first occurrence of x
    ListItr find(int x);		//Returns an iterator that points to
    // the first occurrence of x, else
    // return a blank iterator

    int size() const; //Returns the number of elements in the list


private:
    ListNode *head, *tail;	//indicates beginning and end of the list
    int count;			//#of elements in list
    friend class ListItr;
};

// printList: non-member function prototype
void printList(List& source, bool direction);
//prints list forwards when direction is true
//or backwards when direction is false
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef LISTITR_H
#define LISTITR_H

#include "ListNode.h"
#include "List.h"

class ListItr {
public:
    ListItr();			//Constructor
    ListItr(ListNode* theNode);	// One parameter constructor
    bool isPastEnd() const;	//Returns true if past end position
    // in list, else false
    bool isPastBeginning() const;//Returns true if past first position
    // in list, else false
    void moveForward();	//Advances current to next position in list
    //(unless already past end of list)
    void moveBackward();	//Moves current back to previous position
    // in list (unless already past beginning of
    // list)
    int retrieve() const;	//Returns item in current position

private:
    ListNode* current;		//holds the position in the list
    friend class List;	// List class needs access to “current”
    // ListNode's private data members
};

#endif 


Any help would be appreciated.
Topic archived. No new replies allowed.