On 13 Mar, 05:46, "finer" <finerrecli...@gmail.comwrote:
i'm new to C#, but i'm trying to write a circular doubly linked list.
theres a bug in my code somewhere (i think in my find() method or
ToGo() method) that causes an endless loop after i insert a node in
the middle of the list.
anyone care to take a look? i'm stumped. i appreciate any help.
source code:http://www.cse.buffalo.edu/~dhfine/linkedlist.txt
thanks.
-dave
Your list goes:
0->1->2->3->4->7->5->6
but backwards it goes:
6->5->4->3->2->1->0
I made the following change and it seemed to work.
public void Add(int i)
{
//GoTo(length-1);
if(current.Next == null)
{
current.Next = new Node(current, null, i);
current = current.Next;
}
else
{
current.Next.Previous = new Node(current, current.Next,i);
current.Next = current.Next.Previous; //<--- new
current = current.Next;
}
length++;
index++;
}