A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Java in General
Author
Reverse queue by using stack
Luke Forga
Greenhorn
Joined: Jul 17, 2005
Posts: 11
posted
Jul 24, 2005 17:16:00
0
Could someone help me put together a method which uses a stack to reverse the order of elements in a queue. This can be a generic method...as I will tweak it for implementation. Thanks in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24040
13
I like...
posted
Jul 24, 2005 18:53:00
0
Like this, you mean?
while (queue is not empty) stack.push(queue.next()) while (stack is not empty) queue.add(stack.pop())
[Jess in Action]
[AskingGoodQuestions]
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26141
66
I like...
posted
Jul 24, 2005 18:57:00
0
Luke,
If this isn't for school, you could use the Stack class. It even uses generics in Java 5.0.
[
Blog
] [
JavaRanch FAQ
] [
How To Ask Questions The Smart Way
] [
Book Promos
]
Blogging on Certs:
SCEA Part 1
,
Part 2 & 3
,
Core Spring 3
,
OCAJP
,
OCPJP beta
,
TOGAF part 1
and
part 2
I agree. Here's the link:
http://aspose.com/file-tools
subject: Reverse queue by using stack
Similar Threads
Please help!!!
advantage stack over linked list or queue
Stack and Queue Implementation
java problem stack
Usage areas for stacks and queues
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter