skip to main
|
skip to sidebar
The Riddle Spot
Wednesday, April 25, 2007
#31
How can you reverse a linked list without using any more memory?
Answer:
iterative
loop curr->next = prev;
prev = curr;
curr = next;
next = curr->next
endloop
recursive
reverse(ptr)
if (ptr->next == NULL) return ptr;
temp = reverse(ptr->next);
temp->next = ptr;
return ptr;
end
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
powered by
arnabpal.blogspot.com
Search
Labels
bit twiddling
(4)
data stuctures
(2)
logic
(18)
numbers
(7)
picture clues
(7)
programming
(14)
series
(3)
words
(7)
No comments:
Post a Comment