Java Reference
In-Depth Information
9.
an integer array post is used to hold the postfix form of an arithmetic expression such that
the following items are true:
a positive number represents an operand
-1 represents +
-2 represents -
-3 represents *
-4 represents /
0 indicates the end of the expression
Show the contents of post for the expression (2 + 3) * (8 / 4) - 6 .
Write a function eval that, given post , returns the value of the expression.
10.
an input line contains a word consisting of lowercase letters only. explain how a stack can be
used to determine whether the word is a palindrome.
11.
Show how to implement a queue using two stacks.
12.
Show how to implement a stack using two queues.
13.
a priority queue is one in which items are added to the queue based on a priority number.
Jobs with higher-priority numbers are closer to the head of the queue than those with lower-
priority numbers. a job is added to the queue in front of all jobs of lower priority but after all
jobs of greater or equal priority.
Write classes to implement a priority queue. each item in the queue has a job number
(integer) and a priority number. Implement, at least, the following: (i) add a job in its
appropriate place in the queue, (ii) delete the job at the head of the queue, and (iii) given a job
number, remove that job from the queue.
ensure your methods work regardless of the state of the queue.
14.
a stack, S1 , contains some numbers in arbitrary order. using another stack, S2 , for temporary
storage, show how to sort the numbers in S1 such that the smallest is at the top of S1 and
the largest is at the bottom.
Search WWH ::




Custom Search