creating simple queues

How do i remove an item from the middle of a queue?

i am a newbie so please explain how this can be done and examples of simple queues would be excellent!

thanks

dd
digitaldestruction66Asked:
Who is Participating?
 
Venci75Connect With a Mentor Commented:
try this class:

import java.util.*;

public class Queue {
  private Vector items;
  public Queue() {
      items = new Vector();
  }

  public void enqueue(Object o) {
      items.add(items.size(), o);
  }

  public Object dequeue(Object o) {
      return items.remove(0);
  }

  public void removeAt(int pos) {
      items.remove(pos);
  }
}
0
 
TimYatesCommented:
public void enqueue(Object o) {
     items.addElement(o);
 }

Works just as well
0
 
jerelwCommented:
Iterate through your linked list, and when you find the item you want to remove set the previous item's next to the next item.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
mrowkaCommented:
you can use the class LinkedList directly for modelling
queues, have a look at

http://java.sun.com/docs/books/tutorial/collections/implementations/general.html
and
http://java.sun.com/products/jdk/1.2/docs/api/java/util/LinkedList.html

for a more in depth explanation of collections:
http://www.mindview.net/Books/TIJ/
0
 
Venci75Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: Venci75
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.