尝试在 C# 中从队列中添加和删除节点。但是,当尝试使用时,front.Next
我得到一个编译器错误,即不包含定义。
class Queue<T>
{
int count = 0;
Node<T> front = null;
Node<T> end = null;
public void Enqueue(T obj)
{
if (count == 0)
{
front = new Node<T>(obj);
}
else
{
Node<T> newEnd = new Node<T>(obj);
newEnd.Next = end;
count++;
end = newEnd;
}
}
public T Dequeue(T obj)
{
Node<T> newFront = new Node<T>(obj);
newFront = front.Next;
count--;
front = newFront;
return front;
}
}