Access Millions of academic & study documents

3 Simulate the action of the algorithm for checking delimiters for

Content type
User Generated
Showing Page:
1/13
3. Simulate the action of the algorithm for checking
delimiters for each of the following strings by showing the
contents of the stack at each point. Do not write code. a.
{[A+B]-[(C-D)] b. ((H) * {([J+K])})
4. Write code to determine whether an input character
string is of the form xCy where x is a string consisting of
the letters A and B and y is the reverse of the x (i.e. if
x=ABABBA then y must equal ABBABA, eg.
ABABBACABBABA). At each point you may read only the
next character in the string.
5. Write code to determine whether an input character
string is of the form A D bD cD ... Dz Where each string a,
b, ...z is of the form of the string define in Exercise 4.
(Thus a string is in the proper form if it consists of any
number of such strings separated by the character D, e.g.
ABBCBBADACADBABCBABDAABACABAA.) At each point
you may read only the next character in the string, i.e. you
must process the string on a left to right basis. You may
not use string functions.
6. Design and implement a stack in Java in which each
item on the stack is a varying number of integers. Choose
a Java data structure to implement your stack and design
push and pop methods for it. You may not use library
functions.
7. Consider a language that does not have arrays but does
have stacks as a data type. That is, one can declare stack
s; The push, pop, empty, and peek operations are defined.
Write code to show how a one- dimensional array can be
implemented by using these operations on two stacks. You
need to start by thinking in terms of the operations we do
on arrays.
8. Design a method for keeping two stacks within a single
linear array s[SPACESIZE] so that neither stack overflows
until all of memory is used and an entire stack is never
shifted to a different location within the array. Write Java

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/13
methods push1, push2, pop1, and pop2 to manipulate the
two stacks. (Hint: the two stacks grow toward each other.)
9. Transform each of the following expressions to prefix
and postfix. Do not write code. a. (A+B)*(C$(D-E)+F)-G b.
A+(((B-C)*(D-E)+F)/G)$(H-J)
10. Transform each of the following expressions to infix.
Do not write code.
a. ++A-*$BCD/+EF*GHI
b. +-$ABC*D**EFG
c. AB-C+DEF-+$
d. ABCDE-+$*EF*-
11. Apply the evaluation algorithm in the text to evaluate
the following postfix expressions. Do not write code.
Assume A=1, B=2, and C=3.
a. AB+C-BA+C$-
b. ABC+*CBA-+*
12. Write a prefix method to accept an infix string and
create the prefix form of that string, assuming that the
string is read from right to left and that the prefix string is
created from right to left.
Solution
6. Design and implement a stack in Java in which each
item on the stack is a varying number of integers. Choose
a Java data structure to implement your stack and design
push and pop methods for it. You may not use library
functions.

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/13

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 13 pages?
Access Now
Unformatted Attachment Preview
3. Simulate the action of the algorithm for checking delimiters for each of the following strings by showing the contents of the stack at each point. Do not write code. a. {[A+B]-[(C-D)] b. ((H) * {([J+K])}) 4. Write code to determine whether an input character string is of the form xCy where x is a string consisting of the letters ‘A’ and ‘B’ and y is the reverse of the x (i.e. if x=”ABABBA” then y must equal “ABBABA”, eg. ABABBACABBABA). At each point you may read only the next character in the string. 5. Write code to determine whether an input character string is of the form A D bD cD ... Dz Where each string a, b, ...z is of the form of the string define in Exercise 4. (Thus a string is in the proper form if it consists of any number of such strings separated by the character ‘D’, e.g. ABBCBBADACADBABCBABDAABACABAA.) At each point you may read only the next character in the string, i.e. you must process the string on a left to right basis. You may not use string functions. 6. Design and implement a stack in Java in which each item on the stack is a varying number of integers. Choose a Java data structure to implement your stack and design push and pop methods for it. You may not use library functions. 7. Consider a language that does not have ar rays but does have stacks as a data type. That is, one can declare stack s; The push, pop, empty, and peek operations are defined. Write code to show how a one- dimensional array can be implemented by using th ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4