티스토리 뷰
var node = new DoublyLinkedListNode(); node.data = data; if (head == null) { return node; } else if (data <= head.data) { node.next = head; head.prev = node; return node; } else { var rest = sortedInsert(head.next, data); head.next = rest; rest.prev = head; return head; }
function insertNodeAtPosition(head, data, position) { var curr = head; var prev = null; var node = new SinglyLinkedListNode(); node.data = data;
var i = 0; while (i < position) { prev = curr; curr = curr.next; if (curr == null) { break;} i++; } node.next = curr; prev.next = node; return head; } |