0% found this document useful (0 votes)
10 views2 pages

SIM - Data Structures, Sheet 5, AU

Uploaded by

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

SIM - Data Structures, Sheet 5, AU

Uploaded by

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

Alexandria University

Faculty of Science
SIM Program, Fall 2024-2025
Data Structures

Introduction to Data Structures


Array-based Stack, and Applications
Sheet 5

Exercise 1: Basic Array-Based Stack


Write a Java class that implements a basic array-based stack. Use an array to store the elements
of the stack. Your class should include the following methods:
• push(element): Add an element to the top of the stack.
• pop(): Remove and return the element from the top of the stack.
• isEmpty(): Check if the stack is empty.

Exercise 2: Dynamic Array-Based Stack


Create a dynamic array-based stack implementation that automatically increases its capacity when
it’s about to become full. When the stack reaches a certain capacity limit, create a new larger array
and copy the elements from the old array to the new one.

Exercise 3: Stack Clear Method


Implement a clear method in your array-based stack that removes all elements from the stack.

Exercise 4: Stack Copy


Write a method to create a copy of an existing array-based stack. The copy should have the same
elements in the same order but should be a separate stack object with its own array.

Exercise 5: Balanced Parentheses Validator


Write a Java method using your stack implementation to check if a string of parentheses (e.g.,
{[()]}) is balanced. Return true for balanced strings and false otherwise.
Sample Input:
ab[c]de
Expected Output:
true

1
Sample Input:
a[b{c}d]e}
Expected Output:
false

Exercise 6: String Reversal using Stack


Create a method that uses an array-based stack to reverse the elements in an array. Push each
element of the array onto the stack and then pop the elements to create a reversed array.

Sample Input:
hello
Expected Output:
olleh

You might also like