You also need to override add method of the LinkedList and add to the
head to the list (as oppose to adding to the tail of the list).
Main Topics
Browse All TopicsHi experts, the below code is of a single linked list.
I need to implement a queue (FIFO) from this very code.
Can you please tell me what I need to add and change in this code to make it a stack class?
Please no references to other websites, I have already looked, and I would like to make use of my existing code.
Thanks,
Dennis
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Sorry there was a typo in my description.
It should have read:
Hi experts, the below code is of a single linked list.
I need to implement a queue (FIFO) from this very code.
Can you please tell me what I need to add and change in this code to make it a queue class?
Please no references to other websites, I have already looked, and I would like to make use of my existing code.
Thanks,
Dennis
Please update your answers so I can reward points. Thanks!
public class Queue
{
private LinkedList list = new LinkedList();
// now add your Queue methods as wrappers on list
public int size()
// post: returns the number of elements in this Queue.
{
return list.size();
}
public void EnqueueData(Word data)
{
list.add(data);
}
public Word DequeueData()
{
Word result = list.get(1); // As You have implemented 1 as starting index
list.remove(1);
return result;
}
}
Business Accounts
Answer for Membership
by: objectsPosted on 2009-02-04 at 18:45:08ID: 23556017
public class Queue
{
private LinkedList list = new LinkedList();
// now add your public class Stack
{
private LinkedList list = new LinkedList();
// now add your Stack methods and pave them operate on list
public void push(Object o)
{
list.add(o);
}
public Object pop()
{
Object result = list.get(0);
list.remove(0);
return result;
}