![]() |
reversing doublely linked list
To reverse the list i need to "flip" the prev next "pointers" for each node and moving the head pointer. i keep doing this until the head pointer is null. the code i have is half give half done by me. the method to reverse reversedList was give. i dont understand what/how the dot notation is doing inside the for loop. I dont have to worry about proper OOP on this one so im guessing that has to do some thing with it.
:
public class TestDLLNode :
public class DLLNode |
i figured out how to reverse it myself. i rewrote the method.
:
public static DLLNode reversedList(DLLNode head)now i need to make it into a recursive function. im not sure how to do this. when the method calls it self it will be passing curr to the next method. but when the recursion stops when the next curr is null what will be pasted back to the other called methods? I dont know how sort out the recursion. |
well i figured it out all by myself. it took about two hours but I understand how to approach problems better now. instead of getting frustrated and asking and waiting for help i got out the old paper and pen and started drawing pictures showing what was happening. so here it is.
:
public class TestDLLNode2 |
Good work, mrynit and good job posting the result for the next person.
|
| All times are GMT -5. The time now is 2:29 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC