이중 연결 목록에서 주어진 노드 ("Jack"이라는 노드)를 제거하는 메서드를 만들어야합니다.이중 연결된 목록에서 노드를 제거하는 방법은 무엇입니까?
연결리스트 클래스 :
class DoublyLinkedList
{
public Node head, current;
public void AddNode(object n) // add a new node
{
if (head == null)
{
head = new Node(n); //head is pointed to the 1st node in list
current = head;
}
else
{
while (current.next != null)
{
current = current.next;
}
current.next = new Node(n, current); //current is pointed to the newly added node
}
}
public void RemoveNode(object n)
{
}
public String PrintNode() // print nodes
{
String Output = "";
Node printNode = head;
if (printNode != null)
{
while (printNode != null)
{
Output += printNode.data.ToString() + "\r\n";
printNode = printNode.next;
}
}
else
{
Output += "No items in Doubly Linked List";
}
return Output;
}
}
버튼 코드를 실행 : 당신이 볼 수있는 그리고 내가 "잭"노드를 제거 할 나는 이미 3 개 노드를 추가 한
여기 내 코드입니다.
private void btnExecute_Click(object sender, EventArgs e)
{
DoublyLinkedList dll = new DoublyLinkedList();
//add new nodes
dll.AddNode("Tom");
dll.AddNode("Jack");
dll.AddNode("Mary");
//print nodes
txtOutput.Text = dll.PrintNode();
}
@deviantfan 문제는 노드를 제거하는 방법을 만드는 방법을 모르겠다는 것입니다. – Maattt
@nintendojunkie 어떻게해야할지 모르겠으므로 아무 것도 시도하지 않았습니다. 매우 새로운 것입니다. – Maattt
"이 문제를 진단하기에 충분한 정보가 부족합니다."라고이 질문을 마무리 짓는 사람은 누구나 투표 할 수 있습니다. - 분명히, 문제를 진단하기에 충분한 정보가 있습니다. 왜 이것이 닫혀 야하는지 모르겠습니다. – dcastro