我的问题是这个。我有一个学校作业,要求我将一个新方法添加到给定的链接链接类中,并且我不允许对我当前的链接列表类进行任何更改
iii. RemoveParcelAtPosition(int n)
:此方法将删除链表中位置 n 处的节点。假设链表的第一个节点的位置编号为 1,第二个节点的位置编号为 2,依此类推。
class LinkedList
{
private Node head; // first node in the linked list
private int count;
public int Count
{
get { return count; }
set { count = value; }
}
public Node Head
{
get { return head; }
}
public LinkedList()
{
head = null; // creates an empty linked list
count = 0;
}
public void AddFront(int n)
{
Node newNode = new Node(n);
newNode.Link = head;
head = newNode;
count++;
}
public void DeleteFront()
{
if (count > 0)
{
Node temp = head;
head = temp.Link;
temp = null;
count--;
}
}
}