### Learning C++

Posted:

**Thu Jun 28, 2012 3:51 am**People!! I can say I am re-starting in C++. My friend Robbin has been orientating me. But... I can not molest him more... The problem is the next. I has been doing some exercises were I have to use a queue. Now... I has been receiving Runtime Error in these exercises. I supouse the problem is in my queue. Pleace, if you can do any appoint about any suggestion or error, please, do it!! My queue with the Robbin´s help is the next:

Code: Select all

```
template <class T>
class Node
{
public:
T Value;
Node(T);
Node<T>* Next;
};
template <class T>
Node<T>::Node(T val)
{
Value = val;
Next = NULL;
}
template <class T>
class Queue
{
Node<T>* act;
Node<T>* last;
public:
Queue();
~Queue();
void Enqueue(T);
bool Dequeue(T&);
};
template <class T>
Queue<T>::Queue()
{
act = NULL;
last = NULL;
}
template <class T>
Queue<T>::~Queue()
{
Node<T> * nodito=act;
while(act!=NULL)
{
act=act->Next;
nodito->Next=NULL;
delete nodito;
nodito=act;
}
delete act;
act=NULL;
last=NULL;
}
template <class T>
void Queue<T>::Enqueue(T val)
{
if(act!=NULL)
{
last->Next = new Node<T>(val);
last = last->Next;
}
else
{
last = new Node<T>(val);
act = last;
}
}
template <class T>
bool Queue<T>::Dequeue(T &result)
{
if(act == NULL)return false;
result = act->Value;
Node<T>* temp = act;
act = act->Next;
temp = NULL;
delete temp;
if(act == NULL)delete last;
return true;
}
```