"can you write a method to reverse a linked list?"
"sure!!" at last! something i can answer with confidence..*sigh*
"ok, lets make it even simpler.. reverse a doubly linked list"
"hmmm!" hello! what does he take me for? 7th grader?
"you are thinking too long for this..."
"yeah, i know. how do you like an out-of-the-box answer as opposed to the ordinary 7th-grader-solution?"
"sure..surprise me!"
"ok, here goes...
class DoublyLinkedList
{
protected:
Node pointers[2]; // in lieu of next & previous pointers
bool direction = false;
// all the other standard doubly linked list stuff
public:
void ReverseList()
{
// make the last node as the starting node
direction = !direction;
}
Node *next()
{
return pointers[direction];
}
Node *previous()
{
return pointers[!direction];
}
};
....there! an constant order algo for reversing a doubly linked list."
"hahaha... really good solution."
P.S: Me sorry, me not explaining for the people who do not understand programming. And yeah, me do realise that me creativity has been reduced to writing silly programming tricks in me blog :( Me'll be back with some good posts and some good news.
9 owls
Thursday, July 06, 2006 - 06:26