Browsing the topic Linked Lists
Write a C function to reverse a given Doubly Linked List See below diagrams for example.
Read More »Write a removeDuplicates() function which takes a list and deletes any duplicate nodes from the list. The list is not sorted.
Read More »Write a removeDuplicates() function which takes a list sorted in non-decreasing order and deletes any duplicate nodes from the list. The list should only be traversed once.
Read More »Note that the question is only about printing the reverse. To reverse the list itself see this Difficulty Level: Rookie
Read More »Write a function to get the intersection point of two Linked Lists.
53 Comments | Filed under Linked ListsThere are two singly linked lists in a system. By some programming error the end node of one of the linked list got linked into the second list, forming a inverted Y shaped list. Write a program to get the point where two linked list merge.
Read More »Given a linked list which is sorted, how will you insert in sorted way
4 Comments | Filed under Linked ListsAlgorithm: Let input linked list is sorted in increasing order.
Read More »Asked by Varun Bhatia.
Read More »You are given a Double Link List with one pointer of each node pointing to the next node just like in a single link list. The second pointer however CAN point to any node in the list and not just the previous node. Now write a program in O(n) time to duplicate this list. That [...]
Read More »Asked by Varun Bhatia. Question: Write a recursive function treeToList(Node root) that takes an ordered binary tree and rearranges the internal pointers to make a circular doubly linked list out of the tree nodes.
Read More »Asked by Varun Bhatia.
Read More »Below diagram shows a linked list with a loop
Read More »Iterative Method Iterate trough the linked list. In loop, change next to prev, prev to current and current to next.
Read More »A simple solution is to traverse the linked list until you find the node you want to delete. But this solution requires pointer to the head node which contradicts the problem statement.
Read More »Write a function that counts the number of times a given int occurs in a Linked List
6 Comments | Filed under Linked ListsHere is a solution.
Read More »Algorithm: Iterate through the linked list and delete all the nodes one by one. Main point here is not to access next of the current pointer if current pointer is deleted.
Read More »Given a Linked List and a number n, write a function that returns the value at the nth node from end of the Linked List.
Read More »Method 1: Traverse the whole linked list and count the no. of nodes. Now traverse the list again till count/2 and return the node at count/2.
Read More »Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
9 Comments | Filed under Linked ListsA simple solution is to traverse the linked list until you find the node you want to delete.
Read More »Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at that index position.
Read More »