I build my own Stack data structure in Java (Array + LinkedList implementation) I did'nt just added simple (push/pop) operations, i actually implemented some decent methods in both implementations. I overrode the toString() method so that whenever the object reference is printed, it displays the stack’s contents instead of the default memory address representation. When building using Array the most important concept i learned is dynamic resizing. 🔹 Array-based Dynamic Stack: Generic implementation (Stack<T>) Dynamic resizing (capacity doubles when full) push, pop, peek, search trimToSize() for memory optimization reverse() using two-pointer technique swapTop() utility method clone() for deep copy pushAll() with varargs & collections popMultiple() for batch operations 🔹 Linked List-based Stack Generic stack with Comparable support Efficient push / pop using head pointer contains() search operation toArray() conversion clone() while preserving order sort() functionality using Collections.sort() Batch operations like pushAll() and pop(k) 💡 Key concepts practiced Generics in Java Dynamic memory management Custom exception handling Linked list node design Time complexity considerations (O(1) push/pop) Designing reusable APIs This exercise helped me understand how real data structures work internally, instead of just using library implementations. View comment section for the code on github. Next, I'm planning to implement: Queue (Array + Linked List) Deque Iterator support for custom data structures Always open to feedback, suggestions, or improvements from experienced developers. #Java #DataStructures #DSA #ComputerScience #SoftwareEngineering #LearningInPublic #JavaDeveloper

To view or add a comment, sign in

Explore content categories