Solved

creating simple queues

Posted on 2002-04-15
6
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Title # Comments Views Activity
Error in @AspectJ Based AOP with Spring 2 24
CSV file parsing thru Java 13 40
hashmap order 17 42
Java class and jar 3 42
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

726 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