I'm currently trying to implement Priority queue using Binary search tree. I have the following header file:
template <class T>
class BSTQueue
{
private:
struct Tree
{
T data;
int priority;
Tree* lt;
Tree* rt;
Tree(T Data, int Priority, Tree* left = nullptr, Tree* right = nullptr)
{
data = Data; priority = Priority; lt = left; rt = right;
}
};
Tree* head = nullptr;
Tree* insert(Tree* current, T data, int priority);
};
The problem is that function insert in .cpp generates errors. My .cpp file is the following:
#pragma once
#include "BSTQueue.h"
template<class T>
BSTQueue<T>::Tree* BSTQueue<T>::insert(Tree* current, T data, int priority)
{
if (current == nullptr)
{
return new Tree(data, priority, nullptr, nullptr);
}
if (priority <= current->priority)
{
current->lt = insert(current->lt, data, priority);
}
else
{
current->rt = insert(current->rt, data, priority);
}
return current;
}
And the errors:
- Error C2447 '{': missing function header (old-style formal list?)
- Error C2143 syntax error: missing ';' before '{'
- Error C2061 syntax error: identifier 'Tree'
I have no idea what should I do in order to fix them. Maybe someone knows what to do??