Question:
Write a code for implementation of doubly linked list with use of single pointer in each node
Answer:
Store an extra integer which stores the X-or value of addresses of previous node and the next node. Since you have the option of storing one pointer, you can easily retrieve the address of the other node {either previous or next} by performing X-or between the stored integer and the node address (stored one). Source: CoolInterview.com
Why only XOR? We can also store diff of two pointers that will also take same space and time. Source: CoolInterview.com
Answered by: Monu | Date: 8/10/2009
| Contact Monu
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|