CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Building Interactive UIs with ASP.NET Ajax: Rebinding Client-Side Events After a Partial Page Postback
  • Speed Up Repetitive Insert, Update, and Delete Query Statements
  • Binding Data to Silverlight 4.0 Controls Using ASP.NET MVC Framework 2.0
  • ADO.NET Data Services in the .NET Framework

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > .NET Programming > C-Sharp Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C-Sharp Programming Post questions, answers, and comments about C#.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old February 19th, 2010, 07:24 AM
    JoeJack222 JoeJack222 is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 5
    JoeJack222 is an unknown quantity at this point (<10)
    Need a bit of help with Link-list

    I basically need help using a link-list to implement a certain number of strings, I would like each element to be link to the next node. so far I have:

    Class ListNode
    {
    string x;
    ListNode Next;
    }

    Class List
    {
    ListNode First;
    }

    That will take care of linking the nodes but i need guidance on where to go from here. Is link-list the way to go, how should I create a class to insert the strings?
    Reply With Quote
      #2    
    Old February 19th, 2010, 07:35 AM
    nelo nelo is offline
    Senior Member
     
    Join Date: Nov 2002
    Location: .NET 3.5 VS2008
    Posts: 1,039
    nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)
    Re: Need a bit of help with Link-list

    Hi. Why do actually need to link the items? What do you intend to do with the list? That would determine whether or not a linkd list is the way to go.
    Reply With Quote
      #3    
    Old February 19th, 2010, 07:50 AM
    JoeJack222 JoeJack222 is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 5
    JoeJack222 is an unknown quantity at this point (<10)
    Re: Need a bit of help with Link-list

    Eventually I want to insert or remove elements in a list without impacting all the elements at once. I think using Linklist will work the best for the situation, just unsure about the implementation of x number of strings, while each element is connected to the next node.

    Afterwards I could find items and replace them with ease
    LinkedListNode<string> node = linked.Find("item");
    linked.AddAfter(node, "inserted");
    But that would be after the strings are implementated.
    Reply With Quote
      #4    
    Old February 19th, 2010, 10:05 AM
    nelo nelo is offline
    Senior Member
     
    Join Date: Nov 2002
    Location: .NET 3.5 VS2008
    Posts: 1,039
    nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)
    Re: Need a bit of help with Link-list

    Quote:
    Originally Posted by JoeJack222
    Eventually I want to insert or remove elements in a list without impacting all the elements at once.
    I'm sure you have a good reason to be concerned about impacting all the elements. But what exactly do you mean by this and why are you specific about? There's nothing you've posted so far to suggest that you would be better of with the LinkedList of a custom type as opposed to a list of strings ala List<String>. With the List<String> (i.e. List<T>) you're note having to define a custom type just encapsulate the string and you've options insert and remove elements at will (including inserting/removing at specific locations). It's a collection to grows as the need arises.
    Reply With Quote
      #5    
    Old February 19th, 2010, 10:21 AM
    JoeJack222 JoeJack222 is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 5
    JoeJack222 is an unknown quantity at this point (<10)
    Re: Need a bit of help with Link-list

    Okay, I suppose an List will work out nicely. but if I wanted to implement some string and each element has a link to the next node, is this still possible with List? I can't figure out the implementation of this implementation class, heh.
    Reply With Quote
      #6    
    Old February 19th, 2010, 10:42 AM
    nelo nelo is offline
    Senior Member
     
    Join Date: Nov 2002
    Location: .NET 3.5 VS2008
    Posts: 1,039
    nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)nelo is a glorious beacon of light (400+)
    Re: Need a bit of help with Link-list

    If you want to have elements that are linked to each other (e.g. you want to model some kind of hierarchy) linked list is the obvious choice. If you need the linked list the .NET framework has one out of the box. It should just as easy to use as the List<T>. Check it out...Linked List
    Reply With Quote
      #7    
    Old February 19th, 2010, 11:06 AM
    JoeJack222 JoeJack222 is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 5
    JoeJack222 is an unknown quantity at this point (<10)
    Re: Need a bit of help with Link-list

    Thank you! this is excellent news. I'm not sure how I will incorporate my other classes, not too familiar with Next and First statements but hopefully i'll figure it out! thank you
    Reply With Quote
      #8    
    Old February 19th, 2010, 11:35 AM
    JoeJack222 JoeJack222 is offline
    Junior Member
     
    Join Date: Feb 2010
    Posts: 5
    JoeJack222 is an unknown quantity at this point (<10)
    Re: Need a bit of help with Link-list

    hmm, still having problems figuring out how to implement the other classes...
    Reply With Quote
      #9    
    Old February 21st, 2010, 05:45 PM
    Arjay's Avatar
    Arjay Arjay is offline
    Moderator / MS MVP
    Power Poster
     
    Join Date: Aug 2004
    Posts: 8,133
    Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)Arjay has a reputation beyond repute (3000+)
    Re: Need a bit of help with Link-list

    Quote:
    Originally Posted by JoeJack222 View Post
    Okay, I suppose an List will work out nicely. but if I wanted to implement some string and each element has a link to the next node, is this still possible with List? I can't figure out the implementation of this implementation class, heh.
    Can you explain why each element needs to know the next element in the list. Isn't this the job of a container rather than an element? Are you solving a real world problem, or is this a student assignment? If the latter, can you explain more in detail what you are trying to solve?
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > .NET Programming > C-Sharp Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    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 02:12 AM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.