Loading...
Core singly-linked list operations in pseudocode.
1procedure TRAVERSE(head)2 current ← head3 while current ≠ NULL do4 visit current.data5 current ← current.next6 end while7end procedure
1procedure INSERT_HEAD(head, value)2 node ← new Node(value)3 node.next ← head4 head ← node5 return head6end procedure
1procedure INSERT_AFTER(node, value)2 if node = NULL then return3 newNode ← new Node(value)4 newNode.next ← node.next5 node.next ← newNode6end procedure
1procedure DELETE_VALUE(head, value)2 if head = NULL then return head3 if head.data = value then4 head ← head.next5 return head6 end if7 prev ← head8 current ← head.next9 while current ≠ NULL do10 if current.data = value then11 prev.next ← current.next12 break13 end if14 prev ← current15 current ← current.next16 end while17 return head18end procedure
1Algorithm InsertBeforeNode(head, targetValue, newData):2 newNode ← CreateNode(newData)3 if head != NULL AND head.data == targetValue:4 newNode.next ← head5 head ← newNode6 return head7 current ← head8 while current != NULL AND current.next != NULL AND current.next.data != targetValue:9 current ← current.next10 if current == NULL OR current.next == NULL:11 PRINT "Target node not found"12 return head13 newNode.next ← current.next14 current.next ← newNode15 return head
1procedure REVERSE(head)2 prev ← NULL3 current ← head4 while current ≠ NULL do5 next ← current.next6 current.next ← prev7 prev ← current8 current ← next9 end while10 head ← prev11 return head12end procedure