Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*******************************ArrayStack********************** public class ArrayStack implements StackADT { private final int MAX = 10; private int top; private T[] stack; ArrayStack() { int top = 0;

image text in transcribed

*******************************ArrayStack**********************

public class ArrayStack implements StackADT {

private final int MAX = 10; private int top; private T[] stack;

ArrayStack() { int top = 0; stack = (T[]) (new Object[MAX]);

}

ArrayStack(int intialCapacity) { int top = 0; stack = (T[]) (new Object[intialCapacity]);

} // @Override

@Override public void push(T element) { stack[top] = element; top++;

}

@Override public String toString() { String result = ""; for (int i = 0; i

public T pop() { double store = 0; top--; return stack[top];

}

@Override public T peek() { return stack[top - 1]; }

@Override public int size() { return top; }

@Override public boolean isEmpty() { return top == 0; } }

Part 2: Using a Stack to Solve Problems 1. Design and Implement a Java program that reads a sentence from the user and prints the sentence with the characters of each word backwards. Use the ArrayStack in part 1 to reverse the characters of each word. A sample output is shown in Figure 1 Note that different sentence will be used for grading. It is required that the ArrayStack class should be utilized in solving this problem. Enter a sentence Hello nice to meet you in CS102 Reversing each word: o1leH ecin ot teem uoy ni 201SC BUILD SUCCESSFUL (total time: 14 seconds) Figure 1:reverse characters

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions