Java Homework

profileelpsy69
Homework.docx

Exercice 1

In this exercise, we will compare 2 classes used to create stacks: ArrayStack and

NodeStack. The necessary files are in the ex1 folder. 2 files are provided to be able to compare these classes: tryStack1.java and tryStack2.java.

To do:

1. Compile and run tryStack1

2. Compile and run tryStack2

3. Based on the results obtained and the code provided, answer the following questions

:

• What can we say about the execution of tryStack1 and tryStack2?

• Describe the flow of the call to tryStack1 and tryStack2.

• What are the implementation differences between tryStack1 and tryStack2?

• What did we want to highlight?

Exercise 2: Implementing doubly linked lists

In this exercise, we will implement a class to create and manage doubly lists

chained. The necessary files are in the ex2 folder.

The code for doubly linked lists is in the DLinkedList.java file. However, 2

functions have not been implemented: InsertNode (ListNode nNode, ListNode pAfter) and

RemoveNode (ListNode nNode).

The objective of this exercise is to implement the 2 missing methods.

To do:

1. Implement the InsertNode (ListNode nNode, ListNode pAfter) method.

This method inserts the nNode node after the pAfter node in the current list.

2. Implement the RemoveNode (ListNode nNode) method.

This method removes the nNode node from the current list.

3. Compile and run the TestDLinkedList.java file to validate your implementation.

Exercise 3: Using batteries

In this exercise, we will use a stack to verify the correspondence of

opening and closing parentheses in an expression. The necessary files are in the

ex3 folder.

The code to implement is in the bracketsBalance.java file. However, 1 function does not have

been implemented: boolean bBalance (String exp).

The objective of this exercise is to implement the missing method.

Steps to follow

1. Implement the boolean bBalance (String exp) method.

• This method evaluates the expression exp for matching parentheses.

It returns true if the parentheses are well organized, false otherwise.

• Use the stack implementation in ArrayStack.java to help you.

2. Compile the bracketsBalance.java file. Test it with different expressions in order to

validate your implementation.