Given a pointer to a node in a singly linked list, how do you delete the node ?
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.
Fast solution is to copy the data from the next node to the node to be deleted and delete the next node. Something like following.
struct node *temp = node_ptr->next;
...
Wednesday, June 30, 2010
Find vertical sum of given binary tree. Example: Code: 1 / \ 2 3/ \ / \4 5 6 7 The tree has 5 vertical linesVertical-1: nodes-4 => vertical sum is 4Vertical-2: nodes-2 => vertical sum is 2Vertical-3: nodes-1,5,6 => vertical sum is 1+5+6 = 12Vertical-4: nodes-3 => vertical sum is 3Vertical-5: nodes-7 => vertical sum is 7We need to output: 4 2 12 3 7 We can do an inorder traversal and hash the column....
Write a program to shuffle an pack of cards in the most efficient way. This question can be asked in several flavors.
Knuth Shuffle / Fisher-Yates Shuffle(Modified version by Durstenfeld) algorithm is the answer to all the trick questions. So how does this algorithm work ?
Fisher and Yates’ original method was designed to be implemented using pencil and paper, with a precomputed table of random numbers as the source of randomness. Modern...
Subscribe to:
Posts (Atom)