How to print the values of pointers

Hey guys I'm trying to figure out how can print the values in a linked list every time I add a new node. I have been trying to think of how I can accomplish this for a couple hours and can't seem to figure out how to print anything but the value in the head. Any tips or tricks on how I can get the values to print would be greatly appreciated!

The retrieve function is where I'm trying to get the value to print.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  template <typename T>
class Deque{
private:
        int count;
        Node<T>* head;
        Node<T>* tail;

public:
        Deque();
        Deque(const Deque<T> &); //copy constructor
        Deque<T>& operator=(const Deque<T> &);
        //Or Deque<T> operator=(const Deque<T>);
   //return type should be the same as the parameter type

       ~Deque();

        int size() const;
        bool isEmpty() const;
        void clear();
        void traverse(void (*visit)(T &));

        Error_code retrieve(T &x) const;
        Error_code removeHead(const T &x);
        Error_code removeTail(const T &x);
        Error_code insertHead(const T &x);
        Error_code insertTail(const T &x);
};

template <typename T>
Deque<T>::Deque()

{
   count = 0;
   head = NULL;
   tail = NULL;
}

template <typename T>
int Deque<T>::size() const
{
 return count;
}


template <typename T>
void Deque<T>::clear()
/*
Post: The List is cleared.
*/
{
   Node<T> *p, *q;

   for (p = head; p; p = q) {
      q = p->next;
      delete p;
   }
   count = 0;
   head = NULL;
}


template<typename T>
void Deque<T>::traverse(void (*visit)(T &))
{
  Node<T> *q;
  for(q=head;q; q->next)
       (*visit)(q->entry);

}

//print values
template<typename T>
Error_code Deque<T>::retrieve(T &x) const
{
 Node<T> *p;
 p = head->next;
 x= p->entry;
 p=head->next

return success;
}

template <typename T>
Error_code Deque<T>::insertHead(const T &x)
{
  Node<T> *new_node, *previous, *following;
  if(count==0)
   {
      previous = NULL;
      following = NULL;
      new_node = new Node<T>(x,previous,following);

      head = new_node;
      tail = head;
      count++;
   }
  else
      {
       previous = NULL;
       new_node = new Node<T>(x,previous,head);
       head->prev = new_node;
       head = new_node;
       count++;
      }
      return success;
}


template <typename T>
Deque<T>::~Deque()
/*
Post: The List is empty: all entries have been removed.
*/
{
   clear();
}


#include<iostream>
#include "utility.h"
#include "Node.h"
#include "Deque.h"

using namespace std;

int main(){

Deque<int> dei;

dei.insertHead(2);
dei.insertHead(3);
dei.insertHead(4);


  int x;
  dei.retrieve(x);
  cout<<x<<endl;

};
Topic archived. No new replies allowed.