โปรดดูรหัสต่อไปนี้และแจ้งให้เราทราบว่ามีอะไรผิดปกติหรือไม่ ฉันกำลังพยายามแทรกโหนดในตำแหน่งเฉพาะในรายการที่เชื่อมโยง เราจำเป็นต้องส่งคืนการอ้างอิงไปยังโหนดหลักหลังจากแทรกแล้ว
Node InsertNth(Node head, int data, int position) {
Node newNode = new Node();
newNode.data = data;
if(head==null){
newNode.next = head;
return newNode;
}
Node first = head;
while(position > 0 && head.next!=null){
head = head.next;
position -= 1;
}
newNode.next = head;
head = newNode;
return first;
}
newNode
ให้กับสิ่งใดๆ ที่เป็นnext
- person 4castle   schedule 09.11.2016