Go Back   Computer Forums > General Computing > Hardware
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-10-2004, 04:04 PM   #1
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default need some java help

i just dont understand queues

Stacks, Queues and Prefix Evaluation. A prefix expression is one in which we write the operation before the operands; consider the following examples.

Infix Prefix
4 + 5 + 4 5
1 + 2 * 3 + 1 * 2 3
1 + 2 + 13 + 4 + 5 + 16 + + + + + 1 2 13 4 5 16
Invalid + 1
Invalid + 1 2 3

This exercise is designed to let you learn to use a queue and a stack class.

Implement method enqueuePrefix(), which stores the characters input from the keyboard into a queue.

Implement method evaluatePrefix(), which takes a prefix arithmetic expression from the queue and evaluates it using a stack.

For example, for the input " + 1 * 2 0 ", your output (printed on screen) should be 1.

To simplify this problem, you may assume that + and * are the only operators.
Space is the separator.
You should print out error message for an illegal prefix expression.

Hint: 1. You can directly use the LinkedList class as a queue, or you can define a new Queue class, which inherits from LinkedList but with fewer methods.
2. To evaluate a prefix expression, please consult the lecture notes on postfix evaluation and then design a similar evaluation algorithm for prefix expressions.
Sample Run:

Problem 1:
Enter string:
1 2 3 4 5
The reversed string:
5 2 3 4 1

Problem 2:
Enter a prefix expression:
+ 3 11
Value:
14

Enter a prefix expression:
+ + 3 11
Value:
Invalid
__________________

nburvi1 is offline   Reply With Quote
Old 11-10-2004, 06:52 PM   #2
Solid State Member
 
Join Date: Nov 2004
Posts: 6
Send a message via AIM to nburvi1
Default Re: need some java help

can anyone help?
nburvi1 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 03:31 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0