Skip to content

Completed Pre course 1#2417

Open
sanjoli97 wants to merge 2 commits into
super30admin:masterfrom
sanjoli97:master
Open

Completed Pre course 1#2417
sanjoli97 wants to merge 2 commits into
super30admin:masterfrom
sanjoli97:master

Conversation

@sanjoli97
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Exercise_1.java (Array-based Stack):

  • Strengths: Clean implementation with proper encapsulation. The push/pop/peek operations are O(1) as expected. Good use of comments explaining time/space complexity. Proper overflow/underflow handling.
  • Areas for Improvement: The pop() method returns 0 on underflow, which is problematic since 0 could be a valid stack value. Should throw an exception or use a different sentinel value. The a = new int[MAX] in the constructor is redundant since the array is already initialized at declaration.
  • Edge Cases: Not handling null checks or invalid inputs explicitly.

Exercise_2.java (Linked List-based Stack):

  • Strengths: Good O(1) operations for push/pop/peek. Clean node structure. Proper handling of empty stack case.
  • Areas for Improvement: Same issue as Exercise_1 - returning 0 on underflow/empty peek is ambiguous. The push method could return boolean for consistency with typical stack interfaces.
  • Edge Cases: No explicit error handling or exceptions thrown.

Exercise_3.java (Linked List Implementation):

  • Strengths: Good basic linked list implementation. Clean structure with separate Node inner class. Proper traversal logic.
  • Areas for Improvement: The insert method has O(n) time complexity for each insertion (traversing to end), making overall insertion O(n²). Could be optimized using a tail pointer. The method returns the list but doesn't need to since list reference doesn't change. No deletion or search methods implemented.
  • Edge Cases: No validation for null data or empty list handling in printList.

General Observations:

  • All three implementations compile and run correctly for basic use cases
  • Good practice of including time/space complexity comments
  • Could benefit from generic types instead of just int
  • No JUnit tests or edge case testing shown
  • Code formatting is consistent and readable

@sanjoli97 sanjoli97 changed the title Completed Exercise 1 and 2 Completed Pre course 1 Jun 3, 2026
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.

2 participants