Reverse a Linked List - Iterative
Problem:
Given a linked list having n nodes. Reverse the list by nodes.
Solution:
Keep 3 pointers – prev (previous node), curr (current node) and nxt (next node).
1: Initialize prev = null, curr = null, nxt = head.
2: Set curr = nxt.
3: Move nxt to next node pointer.
4: Set curr’s next to prev.
5: Set prev to curr
6: Repeat steps 2-5 till next is not null.
7: Set curr as head pointer of the list
Code: http://www.ideserve.co.in/learn/reverse-a-linked-list-iterative
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Reverse a Linked List - Iterative канала IDeserve
Given a linked list having n nodes. Reverse the list by nodes.
Solution:
Keep 3 pointers – prev (previous node), curr (current node) and nxt (next node).
1: Initialize prev = null, curr = null, nxt = head.
2: Set curr = nxt.
3: Move nxt to next node pointer.
4: Set curr’s next to prev.
5: Set prev to curr
6: Repeat steps 2-5 till next is not null.
7: Set curr as head pointer of the list
Code: http://www.ideserve.co.in/learn/reverse-a-linked-list-iterative
Website: http://www.ideserve.co.in
Facebook: https://www.facebook.com/IDeserve.co.in
Видео Reverse a Linked List - Iterative канала IDeserve
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Programming Interview Question: How to print all diagonal's sums for a given binary tree?Level Order TraversalProgramming Interview Question: Searching a 2D Sorted MatrixImplement a fair coin given an unfair coinBuying and selling stocksBinary SearchMinimum length subarray of an unsorted array sorting which results in complete sorted arrayFind an element in a sorted rotated array without finding pivot (minimum element)Maximum size square sub-matrix with all 1sBuilding Bridges Dynamic ProgrammingLeaders in an arrayFind intersection of two Linked Lists - O(A + B) Time Complexity and O(1) Space ComplexityCreate a balanced Binary Search Tree (BST) from a sorted arrayNext greater element in an arraySpiral level order traversal of a binary treeProgramming Interview Question: Recover Binary Search TreeDetect a loop in a linked listProgramming Interview Question: Find intersection of two Linked ListsFind an element in a sorted rotated arrayDemo of IDeserve web platform www.ideserve.co.in