Implementing Custom Stack with ArrayList

🚀 11/03/26 — Building the Backbone: Custom Stack Implementation Today was a test of resilience. Despite heavy rain and no electricity, I made sure to stay consistent by implementing a Stack from scratch. Even when power is low, the motivation to keep the streak alive is high! 🏗️ Designing a Custom Stack I built a functional Stack using an ArrayList as the underlying container. This structure follows the LIFO (Last-In-First-Out) principle, which is essential for everything from undo buttons to recursion management. The Logic: push(n): Appends an element to the end of the list, which serves as the "top" of the stack. pop(): Removes the element from the last index of the list if it's not empty. top(): Retrieves the value at the last index without removing it. isEmpty(): Checks if the internal list size is zero. Performance Metrics: Time Complexity: O(1) for push, pop, and top operations (average case for ArrayList). Space Complexity: O(N) where N is the number of elements stored. 📊 Implementation Highlights FeatureQueue (March 2nd)Stack (Today)LogicFIFO (First-In-First-Out)LIFO (Last-In-First-Out)ControlHead and Tail pointersSingle "Top" pointer (end of list)Use CaseBFS / BufferingDFS / Undo / Function Calls📈 Consistency Report Consistency isn't just about the days when everything goes right; it's about showing up when things go wrong. Today, even with a machine going down due to low power, completing this implementation reinforces the core principles of memory management I've been studying. Seeing the Stack logic I used iteratively for Trees on March 6th now built from the ground up is another major milestone. Huge thanks to Anuj Kumar (a.k.a CTO Bhaiya on YouTube) for the roadmap. Every bit of code counts toward mastery! My tested Stack implementation is saved (just in time)! 📄👇 #DSA #Java #CodingJourney #Stack #DataStructures #LIFO #Consistency #LearningInPublic #CTOBhaiya

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories