Docsity

Stack using Singly Linked List java, Exercises of Java Programming

Toggle sidebar
bg1
Lab 4
(Stacks)
Exercise 1
Create a generic class Stack<E> using a singly linked list with the following methods:
1. push(E e)
2. E pop()
3. E top()
4. boolean isEmpty()
Exercise 2
Write a method void reverse() that replace the contents of the stack with those same elements but in
reversed order using two temporary stacks.
Exercise 3
Write a method boolean checkParentheses(String s) that checks that the different parenthesis (,{, [,],}, )
in the String s are balanced using the previously created Stack class.
Exercise 4
Write a method String infixToPostfix(String s) that converts an expression from the infix notation to the
postfix notation using the previously created Stack class.
Exercise 5
Write a method int evaluatePostfixExp(String s) that evaluates an expression in a postfix notation using
the previously created Stack class.

Partial preview of the text

Download Stack using Singly Linked List java and more Exercises Java Programming in PDF only on Docsity!

Lab 4

(Stacks)

Exercise 1

Create a generic class Stack using a singly linked list with the following methods:

  1. push(E e)
  2. E pop()
  3. E top()
  4. boolean isEmpty()

Exercise 2

Write a method void reverse() that replace the contents of the stack with those same elements but in reversed order using two temporary stacks.

Exercise 3

Write a method boolean checkParentheses(String s) that checks that the different parenthesis (,{, [,],}, ) in the String s are balanced using the previously created Stack class.

Exercise 4

Write a method String infixToPostfix(String s) that converts an expression from the infix notation to the postfix notation using the previously created Stack class.

Exercise 5

Write a method int evaluatePostfixExp(String s) that evaluates an expression in a postfix notation using the previously created Stack class.