Midterm Project — Data Structure
Exercisel: Write a java program with the following:
- Class ArrayChar that have as private attribute (char[] arr, int size) and it can
apply
all the methods of ArrayList depending on basic array implementation and
algorithm -- ArrayChar can be resizable at any size (similar to be ArrayList but it
is
not).
- Class Stack that can apply all the methods of stack (the implementation is based
on ArrayChar) where the top of stack is the beginning of ArrayChar
- Add method Reverse in stack class to reverse a String of characters (entered as
parameter) based on stack methods (push and pop). You can accept from input
(char or String)
- Method searchFor that can accept also a char or a String you asked for and return
an ArrayList contains the count of each char exists in stack
- Menu that accepts the input from scanner and output the result based on your
choice
- Class main to instance ArrayChar and Stack and apply the code of the menu
NB: The Following sample run explain how program work (read it carefully). And it
should be repeated until you choose to exit.
- Choices from 1 to 6 should be based on ArrayChar and from 7 to 12 should be
based on Stack
Sample Run: The Menu
. Insert in Beginning
. Insert in end
. Insert in particular position
. Delete from beginning
. Delete from end
. Delete from position
. Push
. pop
9. Length
10. Reverse
11.Display
12. Repeated character
0. Exit
CW ~1 on Ud wh
Sample Run: Execution example
Enter your choice: 1
Enter a character: e
c¢ is entered at first
Enter your choice: 2
Enter a character: bed
bed 1s entered at end
Enter your choice: 10
The reverse string is: debc
Enter your choice: 11
The string is: cbed
Enter your choice: 7
Enter a character: b
b is pushed into stuck
Enter your choice: 12
Enter a character to search for: b
b is found: 2 times
Enter your choice: 12
Enter a character to search for: be
b is found: 2 times
e 1s found: 1 time
Enter your choice: 0
Good Bye
Exercise 2:
- Is it possible to replace the Stack project in exercise_1 by a Queue?
- If possible: rewrite the code using LinkedList implementation to do the
same menu.
— If not possible: Explain why