Witam. Czy ktoś może sprawdzić czy mam dobrze napisaną metodę "empty" i destruktor ?? Jakby ktoś by znalazł jakiś błąd w implementacji kolejki to też bym był wdzięczny za wszelkie uwagi.
#include<iostream>
#include<stdexcept>
using namespace std;
template <class T>
class QUEUE
{
struct node
{
T data;
node *next;
node(T x)
{
data: x;
next = NULL;
}
};
typedef node * pnode;
pnode head,tail;
public:
QUEUE();
bool empty()const // czy to jest też dobrze napisane ??
{
return head == NULL;
}
void put(T);
T get();
~QUEUE();
};
template<class T>
QUEUE<T>::QUEUE()
{
head = NULL;
}
template <class T>
void QUEUE<T>::put (T x)
{
if (empty())
head = tail = new node(x);
else
{
pnode pom = tail;
tail = new node(x);
pom ->next =tail;
}
}
template<class T>
T QUEUE<T>::get()
{
if (empty())
throw out_of_range ("Kolejka pusta");
T temp = head -> data;
pnode stara = head;
head = head -> next;
delete stara;
return temp;
}
template <class T> // Czy destruktor jest dobrze napisany ??
QUEUE<T>::~QUEUE()
{
while(head != NULL)
get();
}
int main()
{
system("pause");
return 0;
}