Linked list

This is a discussion on Linked list within the C# Programming forums, part of the General Programming Boards category; Hello, do somebody have an clear and easy to understand example of how to release a simple linked list with ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    47

    Question Linked list


    Hello,
    do somebody have an clear and easy to understand example of how to release a simple linked list with CS.

    i mean the eqivalent to a c example.
    Code:
    typedef struct _myListNode
    {
        _myList *next;
        _myList *prev;
        unsigned long test1;
    } LISTNODE, *PLISTNODE;
    
    LISTNODE *myList;
    
    myList = new LISTNODE;
    etc.


    can somebody help please ?

    Regards,
    Robert

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    Hi all,

    i've found something that is well described and commented.
    for interested go here:
    http://csharpcomputing.com/Tutorials/Lesson9.htm

    Regards,
    Robert

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    The tutorial itself is fine for a linked list tutorial, just don't stay with their interpretation of Exceptions in there, it will fail.

    If you understood linked lists in C#, look up exceptions ( really the same thing as in C++ minus pointers ). Insert some bad values as parameters in these linked list functions and you will see how they work ( and fail to do what is needed in this example )

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    Hello!

    Quote Originally Posted by nvoigt
    . Insert some bad values as parameters in these linked list functions and you will see how they work ( and fail to do what is needed in this example )

    Do you mean stuff like this
    Code:
    G:\coding\cs\linked_list\bin\Debug>linkedlist
    
    Unbehandelte Ausnahme: System.FormatException: Die Eingabezeichenfolge hat das f
    alsche Format.
       at System.Text.StringBuilder.FormatError()
       at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String fo
    rmat, Object[] args)
       at System.String.Format(IFormatProvider provider, String format, Object[] arg
    s)
       at System.IO.TextWriter.WriteLine(String format, Object arg0)
       at System.IO.SyncTextWriter.WriteLine(String format, Object arg0)
       at System.Console.WriteLine(String format, Object arg0)
       at linkedlist.List.move_to_node(Int32 k) in g:\coding\cs\linked_list\Class.cs
    :line 44
       at linkedlist.List.insert_node(ListNode a_node, Int32 position) in g:\coding\
    cs\linked_list\Class.cs:line 52
       at linkedlist.Test.Main() in g:\coding\cs\linked_list\Class.cs:line 130
    
    G:\coding\cs\linked_list\bin\Debug>


    Quote Originally Posted by nvoigt
    . If you understood linked lists in C#,
    Yes the principle is close to the C or C++ version.
    I was expecting some more complex examples (not that this wouldn't be enought, its ok for my tiny project) and more OO style like STL solution for C#.
    ...
    I've never dealed or wanted to deal with exceptions (not in Java nor in C++) somehow i intend to use the classic way.

    Regards,
    Robert

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    another question about the list node class

    Code:
    class ListNode
    {
        public int data;
        public ListNode next;
    };
    wouldn't it be better if this node would be a struct

    Code:
    struct ListNode
    {
        public int data;
        public ListNode next;
    
    
    };
    i'm too unexpierent in c#, what gives better performence or is a more suitable version ?

    Regards,
    Robert

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    A struct always is a value type and therefor would not work with the pointer logic of linked lists.

    BTW: Unlike C, you do not code storage classes yourself in .NET.
    Have a look at the System.Collections namespace, you will find a lot of predefined classes there, like ArrayLists, Hashtables, Stacks, Queues and more.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    Quote Originally Posted by nvoigt
    BTW: Unlike C, you do not code storage classes yourself in .NET.
    Have a look at the System.Collections namespace, you will find a lot of predefined classes there, like ArrayLists, Hashtables, Stacks, Queues and more.
    this is what i meant, but didn't know how to find. This is kinda STL isn't it ?, in pure C# there is the possiblity to do own storage classes or mechanisms, aren't there ?

    What about the performace when for example i want to use the ArrayList for some entries and then within a loop search for an entry ?
    What is faster. Making own Array or using .NET System.Collections ?

    Slowly i get nightmares from all these Namespaces, Classes, Methods etc.

    Regards,
    Robert

  8. #8
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Well, if you need that last bit of performance, the best way is always to try all variants. Theory is nice, but test results are better

    You can write your own storage classes, but if you do, you will find it helpful if all storage classes implement the IList and IEnumerable interfaces.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    nvoigt Thanks a lot for help and suggestions!

    Regards,
    Robert

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 11:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 11:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21