Results 1 to 2 of 2
  1. #1
    RozenKristal is offline Member
    Join Date
    Sep 2012
    Posts
    10
    Rep Power
    0

    Default Create linked list using loop

    I want to make a doubly linked list and I know the numbers of nodes should be in there, how do I going to do so?
    Am I suppose to use a for loop ?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,310
    Blog Entries
    7
    Rep Power
    20

    Default Re: Create linked list using loop

    Strictly speaking, if you know the number of nodes to insert, you don't need any loop at all, but it just looks silly if you have repeated a list.insert(aNode) statement thousand times ... a simple while loop will do:

    Java Code:
    while (moreToInsert())
       list.insert(getNextNode());
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 0
    Last Post: 09-25-2012, 04:07 AM
  2. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 05:37 AM
  3. Replies: 4
    Last Post: 02-21-2011, 09:34 AM
  4. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  5. Replies: 1
    Last Post: 12-03-2009, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •