SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > General > General Topics
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 05-28-07, 12:00 PM   #1
daft
Captain
 
Join Date: Jan 2002
Location: Sweden
Posts: 493
Downloads: 15
Uploads: 0
Default 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. Sorry for the confused description, just ask if somethings unclear.
__________________
And God said: \"Let there be Narrowband!\"
daft is offline   Reply With Quote
Old 05-28-07, 12:22 PM   #2
daft
Captain
 
Join Date: Jan 2002
Location: Sweden
Posts: 493
Downloads: 15
Uploads: 0
Default

Never mind, I read my post twice and managed to find a solution.
__________________
And God said: \"Let there be Narrowband!\"
daft is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:09 AM.


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.