help with linked lists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yolkman
    New Member
    • Sep 2006
    • 14

    #1

    help with linked lists

    I have a constructor public LinkedList(int[]) that will read primitive values in an array and place them in a linked list. How do I go about this?
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by yolkman
    I have a constructor public LinkedList(int[]) that will read primitive values in an array and place them in a linked list. How do I go about this?
    You came up with the constructor, and yet you don't know how to use it?

    And your code will actually create a linked list of arrays, a little different than moving values from an array into a linked list...

    A googlesearch of 'java linked list'

    http://java.sun.com/j2se/1.4.2/docs/...inkedList.html

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Is this a user defined LinkedList then?

      All you need to then is to assign the array values as elements of the linked list.

      Depending on how you implemeted the ListNode,
      Use a for that goes through the array. At each step take two elemets out,
      create two nodes and do something like nodei.next = node(i+1). So the node created with element at i + 1 is assigned the next of the node created with element at i. Of course you should set the first elent accordingly

      Comment

      Working...