Question: Stack Lab In this lab you will demonstrate your ability to be able to use Stack data - structure concept only. You can use java.util.Stack

Stack Lab
In this lab you will demonstrate your ability to be able to use Stack data-structure concept only. You can use java.util.Stack library and no other libraries are allowed. (You are not allowed to use HashMap, TreeMap, List, Node, etc.) For this lab you will read a string that can have a positive integer (let's say n) followed by open parentheses then some string and then close parentheses. Your should use Stack implementation to expand the string by repeating the string inside the parathesis exactly n times and print the string again with its expanded version.
For example:
Input: "Che2(r)y"
Output: Cherry
Assume that:
Input string is always valid
There will be no extra white spaces
Parentheses will be well-formed
string will not contain any digits to be repeated, like: 2(4)
if there is digit that is not having a parentheses immediately after it, then that digit will be ignored. For example: abc3def
Here are some more input/output examples so you know expected input and output.
\table[[Input string,Output string],[5(a)3(bc),aaaaabcbcbc],[2(a3(c)),acccaccc],[2(abc)2(cd)efgh,abcabccdcdefgh],[abc2(cd)mno1(p),abccdcdmnop],[ha2(p)y,happy],[Mi2(s)i2(s)i2(p)i,Mississippi]]
(Hint: Create two Stacks. One to hold Stack of Integer and one to hold Stack of String.)
SpecialString.java
 Stack Lab In this lab you will demonstrate your ability to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!