public:
Queue() : front(0), back(0)
{}
void put(TreeNode *ptn)
{
ListNode *tmp = new ListNode(ptn, 0);
if (back == 0)
front = tmp;
else
back->next = tmp;
back = tmp;
}
TreeNode *get()
{
assert(front);
TreeNode *result = front->ptn;
ListNode *tmp = front->next;
delete front;
front = tmp;
if (front == 0)
back = 0;
return result;
}
I don't understand what put is supposed to do, because we're putting temp in back as well as the front at the beginning and then we're putting temp in the back and to the node pointed by back.