I am sharing this because I could not find a good implementation via google. I hope that this will be of some use to some one. At least to a beginner.
Usage Example;
(This implementation support storing String type LinkedList, but you can change it)
Code: Select all
LinkedList linkedList=new LinkedList();
linkedList.insertFirst("How ");
linkedList.insertFirst("Hello,");
linkedList.insertLast("are ");
linkedList.insertLast("you?");
//reading the linked list;
LLNode temp=linkedList.removeFirst();/*reading this way destroys your linked list*/
/*But I want this behaviour of a queue in my app*/
while(temp!=null){
System.out.println(temp.data);
temp=li.removeFirst();
}
Suggestions are welcome!