[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

creating simple queues

Posted on 2002-04-15
6
Medium Priority
?
239 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 400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

656 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