0% found this document useful (0 votes)
24 views

Data Structure Midterm Lab Project

The document describes a midterm project assignment involving implementing various data structures in Java. It includes: 1. An ArrayChar class that functions similarly to an ArrayList but uses a char array. 2. A Stack class that uses an ArrayChar to implement stack methods like push and pop. 3. A method to reverse a string using the stack. 4. A search method to count characters in the stack. 5. A menu to test the classes and methods. It then asks if the stack can be replaced with a queue, and if so to rewrite it using a LinkedList, or explain why not.

Uploaded by

Samer Kouta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Data Structure Midterm Lab Project

The document describes a midterm project assignment involving implementing various data structures in Java. It includes: 1. An ArrayChar class that functions similarly to an ArrayList but uses a char array. 2. A Stack class that uses an ArrayChar to implement stack methods like push and pop. 3. A method to reverse a string using the stack. 4. A search method to count characters in the stack. 5. A menu to test the classes and methods. It then asks if the stack can be replaced with a queue, and if so to rewrite it using a LinkedList, or explain why not.

Uploaded by

Samer Kouta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like