Artemis 6.6.3 Course Overview Course Management kiu_ana.
idadze
Courses > Fundamentals of Programming (FoP) (WS 2023/24) > Exercises > Counting Brackets
Counting Brackets Easy Start date: 10 days ago
Points: 10 Optional Assessment: automatic
You have not started this exercise yet.
Instructor actions:
Tasks: Communication
Search for a message
Stack
Unresolved Own Reacted Date:
In this assignment, you should employ a stack to determine whether a String is correctly
bracketed. Intuitively, this means that every opening bracket is eventuallly followed by a No messages found
corresponding closing bracket and, vice versa, each closing bracket is preceeded by a
corresponding opening bracket, where the ranges between opening and corresponding
closing brackets are either disjoint or properly nested into each other. Formally, an
expression is correctly bracketed, if it adheres to the following grammar:
correct ::= ( correct ) | [ correct ] | { correct } | correct correct | ϵ (ϵ means empty sequence
of characters)
The expression ([])(){([])} thus is correctly bracketed, while ([)] is not. Additionally, we
allow arbitrary further characters at abritrary positions - as long as theses are not brackets.
1. Stack No results
{} Realize an array based implementation of a stack in the class BracketStack. The initial
length of the array inside the stack should be provided as a parameter to the
constructor. Name the stack pointer stackpointer. Provide methods push (puts a value
onto the stack), pop (extracts the topmost element and returns it) and peek (returns the
topmost element without removing it from the stack) as well as isEmpty (tells whether
the stack is empty). Come up with the appropriate signatures of the methods.
2. checkBraces No results
{} Provide a method public static boolean checkBraces(String input) which
determines whether a given string input is correctly bracketed. For that, you may use
the methods int length() and char charAt(int i) from the class String which return
the length and the character at position i of a string, respectively, together with the
auxiliary method private static boolean matches(char open, char close) from the
template.
Possible solution
Exercise details
Release date: Oct 22, 2023
23:12
Start date: Oct 22, 2023
23:12
Submission due: No due date
About Request change Release notes Privacy Statement Imprint