Skip to content

exercise 1 done - #2434

Open
Keerthi0910 wants to merge 3 commits into
super30admin:masterfrom
Keerthi0910:master
Open

exercise 1 done#2434
Keerthi0910 wants to merge 3 commits into
super30admin:masterfrom
Keerthi0910:master

Conversation

@Keerthi0910

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

The student has provided two implementations of a stack: one using an array (Exercise_1.java) and one using a linked list (Exercise_2.java). Let me evaluate both.

Exercise_1.java (Array-based Stack):

  • Correctness: The implementation is mostly correct. The push, pop, and peek operations work as expected.
  • Issues:
    • throw new Error("...") is not ideal. Should use throw new RuntimeException("...") or a custom exception.
    • The isEmpty() method is defined but never used in the main method.
    • The MAX constant is hardcoded to 1000, which limits flexibility.
  • Time Complexity: O(1) for all operations - correct.
  • Space Complexity: O(n) - correct.

Exercise_2.java (Linked List-based Stack):

  • Correctness: There are syntax errors and missing braces.
  • Issues:
    • this data = data; should be this.data = data; (syntax error)
    • The peek() method is missing a closing brace and the return 0; statement for the empty case.
    • The class is missing a closing brace at the end.
    • The main method is inside the peek() method due to missing braces.
    • StackNode should be a non-static inner class or properly structured.
  • Time Complexity: O(1) for all operations - correct.
  • Space Complexity: O(n) - correct.

General Code Quality Issues:

  • Inconsistent error handling (some methods throw exceptions, others return 0).
  • Missing JavaDoc comments.
  • The isEmpty() method in Exercise_1 is unused.
  • No input validation or testing of edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants