<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d7561468\x26blogName\x3daut+me+aut+nihil\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLACK\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://pichuva.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://pichuva.blogspot.com/\x26vt\x3d-5614881344110247665', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>
aut me aut nihil

aut me aut nihil = Either me or nothing. no,no... me not boosting. me have an inferiority complex and trying to compensate :D 

Thursday, July 06, 2006 - 06:26

Linked list

"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

© Copyright 2006 - S m i t h a