SUBSIM Radio Room Forums

SUBSIM Radio Room Forums (https://www.subsim.com/radioroom/index.php)
-   General Topics (https://www.subsim.com/radioroom/forumdisplay.php?f=175)
-   -   Any C# gurus around? (https://www.subsim.com/radioroom/showthread.php?t=115610)

daft 05-28-07 12:00 PM

Any C# gurus around?
 
If so, you might be able to help out a bit. I'm trying to remove the last node from a linked list, and it works alright until I only have one node remaining in the list. That's were all goes wrong. This is the code I have for the GetLast() - method:

Code:

public LNode<T> GetLast()
        {
            if (head == null)
            {
                return null;
            }
            else
            {
                LNode<T> current = head;

                while (current.Next != null)
                {
                   
                    current = current.Next;

                }

                LNode<T> toGet = current;
                current.Previous.Next = null;
                return toGet;
            }
        }

I know why the last element isn't fetched, it doesn't have a previous node to refer to, so the current.Previous.Next doesn't work. I've stared myself blind at this problem and really would appreciate any halp I can get since Google didn't turn up anything. I tried checking if current.Next == null, but that didn't help. :cry: Sorry for the confused description, just ask if somethings unclear. :)

daft 05-28-07 12:22 PM

Never mind, I read my post twice and managed to find a solution. :)


All times are GMT -5. The time now is 09:06 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 1995- 2025 Subsim®
"Subsim" is a registered trademark, all rights reserved.