Results 1 to 5 of 5
  1. #1
    IT student is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default union in linked list

    Hello every one
    I face aproblem while i writing this program about append one single linked list to the second one(union) can any one tell me the code that help me to complet the program

    code:


    public class linked {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int i,j; /*,n,value*/;
    //Scanner scan = new Scanner(System.in);

    SLLNode current;
    SLLHeader headerNode = new SLLHeader();
    SLLNode firstnode = new SLLNode(3);
    SLLNode secondnode = new SLLNode(20);
    SLLNode thirdnode = new SLLNode(100);

    headerNode.LinktofirstNode = firstnode;
    firstnode.next = secondnode;
    secondnode.next = thirdnode;

    current = HeaderNode.LinktoFirstNode;

    i=1;
    System.out.println("The values stored in the linked list are:");
    while (current != null){
    System.out.println("The value at node " +i +" is " +current.data);
    current = current.next;
    i++;
    }

    SLLNode B;
    SLLHeader BheaderNode = new SLLHeader();
    SLLNode Bfirstnode = new SLLNode(1);
    SLLNode Bsecondnode = new SLLNode(2);
    SLLNode Bthirdnode = new SLLNode(100);

    BheaderNode.LinktoFirstNode = Bfirstnode;
    Bfirstnode.next = Bsecondnode;
    Bsecondnode.next = Bthirdnode;
    B = BheaderNode.LinktoFirstNode;


    j=1;
    System.out.println("The values stored in the second linked list are:");

    while (B != null){
    System.out.println("The value at node " +j +" is " +B.data);

    B = B.next;
    j++;

    }}}

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    3node.next = 4node;

    but do use know the meaning of union?
    if union, elements, exist in both set, show appear once after union

  3. #3
    IT student is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default

    thank you for your help
    but i have two single linked list not one as you understand
    I want to connect between two these
    i now the step but i can not implement it with code
    the steps are
    1- traverse the first SLL
    2- assign the last node of the first linked list to the first node at the second SLL >>
    Last edited by IT student; 12-31-2009 at 12:18 PM.

  4. #4
    IT student is offline Member
    Join Date
    Oct 2009
    Posts
    6
    Rep Power
    0

    Default

    I need more help please>>

  5. #5
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    aehm. well its a programming assignment; but this assignment is unsuitable for java. you dont want implement list structures in java because there are already classes wich provide the nescessary functionality.

    but of course it is important to understand how such list work. we aso had to implement list packages in our study but that was in ada95.

    to fully understand the problem i suggest you implement list in c, ada, or other more imperative language. of course you can do this with java too, but you have to implement a list in an object oriented manner. it's a bit different.
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

Similar Threads

  1. Linked List help
    By alpdog14 in forum New To Java
    Replies: 3
    Last Post: 10-07-2009, 10:34 PM
  2. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 09:53 PM
  3. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 04:15 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 04:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:29 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
  •