Solved

creating simple queues

Posted on 2002-04-15
6
215 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:digitaldestruction66
6 Comments
 
LVL 9

Accepted Solution

by:
Venci75 earned 100 total points
ID: 6941548
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
 
LVL 35

Expert Comment

by:TimYates
ID: 6941716
public void enqueue(Object o) {
     items.addElement(o);
 }

Works just as well
0
 
LVL 3

Expert Comment

by:jerelw
ID: 6942715
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Expert Comment

by:mrowka
ID: 6944658
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
 
LVL 9

Expert Comment

by:Venci75
ID: 7940699
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
 

Expert Comment

by:modulo
ID: 7990872
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question