Results 1 to 5 of 5
Thread: Genrate Single LL from Double LL
- 03-25-2011, 11:23 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 27
- Rep Power
- 0
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();
}
- 03-25-2011, 02:30 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
The LinkedList class does not have a method called printFirst(). Instead, you can do this:
Look at the Java API when you're using the built-in classes: LinkedListJava Code:System.out.println(L1.getFirst());
- 03-25-2011, 03:30 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 27
- Rep Power
- 0
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 03:33 PM.
- 03-26-2011, 04:54 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 27
- Rep Power
- 0
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
- 03-26-2011, 08:18 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 27
- Rep Power
- 0
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 08:20 AM.
Similar Threads
-
How to get a single value from a Map?
By cjw92 in forum New To JavaReplies: 11Last Post: 02-05-2011, 06:44 PM -
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
Check if double is double
By marshalthrone in forum New To JavaReplies: 8Last Post: 09-30-2009, 02:51 PM -
non-static method add(double,double) cannot be referenced from a static context
By cravi85 in forum Java SoftwareReplies: 5Last Post: 03-21-2009, 09:32 PM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks