You are viewing a single comment's thread. Return to all comments →
static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode head, int data, int position) {
SinglyLinkedListNode new_node = new SinglyLinkedListNode(data); SinglyLinkedListNode cnode = head; while(--position > 0) { cnode = cnode.next; } new_node.next = cnode.next; cnode.next = new_node; return head; }
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
static SinglyLinkedListNode insertNodeAtPosition(SinglyLinkedListNode head, int data, int position) {