Results 1 to 5 of 5
  1. #1
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default Genrate Single LL from Double LL

    i created Doubly Linked List with all methods i need , but there is still one question which i really did not understand it very well it said : write a method to create linked list from double linked list using the methods available in myLinkedList(which had the methods that i created), and java.util.LinkedList ?

    can any body explain to me this question ?


    Look this is my main code , My Double Linked List Methods worked probley with me , but when i created the single LL , that am just imported from lib.
    i got an error .. how i can create Single LL with Double LL methods.



    public static void main(String[] args) {
    DLL dll = new DLL();
    LinkedList L1 = new LinkedList();


    dll.insertFirst("A");
    dll.insertFirst("b");
    dll.insertFirst("c");
    dll.insertLast(1);
    dll.insertLast(3);
    dll.insertLast(5);

    dll.deleteFirst();
    dll.deleteLast();

    dll.printFirst();
    dll.printLast();


    L1.addFirst("I");
    L1.addFirst("s");
    L1.addFirst("h");
    L1.printFirst();

    }

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    103
    Rep Power
    0

    Default

    The LinkedList class does not have a method called printFirst(). Instead, you can do this:
    Java Code:
    System.out.println(L1.getFirst());
    Look at the Java API when you're using the built-in classes: LinkedList

  3. #3
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    YUP i know that , but my question is :

    write a method to create linked list from double linked list using the methods available in myLinkedList(which had the methods that i created), and java.util.LinkedList ?

    so i have write method this first require.
    by using methods in DLL and java.util.LinkedList.

    i do not have a lot of info about Linked list , but i know that ..
    i can create simple linked list without using " .getPrev Node" ..
    so the first think i think about it is write this method in the main to create Single Linked List ..

    public static LinkedList singLL(LinkedList L1)
    {

    int a = L1.size();
    for(int K =0;K<=a;K++)
    {
    L1.addFirst("A");
    }
    System.out.println(L1.getFirst());
    return L1;


    }


    but my problem now is /// how i can use DLL methods for SLL that i ALREADY created !!
    Last edited by SHE; 03-25-2011 at 04:33 PM.

  4. #4
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    I know one solution is "iterate through my doubly-linked list and add each element to a java.util.LinkedList" .. can any one explain how i can iterate my DLL although i created by myself

  5. #5
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    WHEN I TRY THIS ONE IS STILL DOES NOT WORK IT RETURNED (0) AS OUTPUT

    //Iterate with the help of while loop
    System.out.println("Iterating with the help of while loop");
    int j=0;
    while (j< dll.size())
    {
    L1.addFirst(j);
    System.out.println( L1.get(j) );
    j++;
    }
    Last edited by SHE; 03-26-2011 at 09:20 AM.

Similar Threads

  1. How to get a single value from a Map?
    By cjw92 in forum New To Java
    Replies: 11
    Last Post: 02-05-2011, 07:44 PM
  2. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 11:40 AM
  3. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 03:51 PM
  4. Replies: 5
    Last Post: 03-21-2009, 10:32 PM
  5. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 09:39 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
  •