badge icon

This article was automatically translated from the original Turkish version.

Article
datastructure.jpg
Stack
Data Structure Type
Linear
Basic Operations
push()pop()peek()isEmpty()isFull()
Application Areas
Software Development and Programming LanguagesData Processing and AlgorithmsOperating SystemsGame DevelopmentArtificial Intelligence and Automation Systems

A stack is a linear data structure that follows the LIFO (Last In, First Out) principle, where the last element added is the first one removed. This means that both insertion and deletion operations occur at only one end.


LIFO (Last In, First Out) Principle

Some practical real world examples of LIFO:

  • When adding a plate to a stack of plates, it is placed on top. When removing a plate, it is taken from the top.
  • In a box where balls are stacked on top of each other, a ball is added or removed from the top.





Types of Stacks

1. Fixed-Size Stack: As the name suggests, a fixed-size stack has a predetermined size and cannot grow or shrink. If the stack is full and an attempt is made to add an element, an overflow error occurs. If the stack is empty and an attempt is made to remove an element, an underflow error occurs.


2. Dynamic-Size Stack: A dynamic-size stack can grow or shrink dynamically. When the stack becomes full, it automatically increases its size to accommodate a new element, and when it becomes empty, it reduces its size. This type of stack is implemented using a linked list because it allows easy resizing of the stack.


Basic Stack Operations

  • push(): Used to add an element to the stack


Push operation in a stack structure (Source: geeksforgeeks.com)


  • pop(): Used to remove an element from the stack


Pop operation in a stack structure (Source: geeksforgeeks.com)


  • peek(): Returns the top element of the stack without removing it.


Peek operation in a stack structure (Credit: geeksforgeeks.com)


  • isEmpty(): Returns true if the stack is empty, otherwise false.


isEmpty operation in a stack structure (Source: geeksforgeeks.com)


  • isFull(): Returns true if the stack is full, otherwise false.


isFull operation in a stack structure (Source: geeksforgeeks.com)



Advantages of Implementing a Stack Using a Linked List

1. Dynamic memory allocation: The size of the stack can be dynamically increased or decreased by adding or removing nodes from the linked list, without requiring a pre-allocated fixed amount of memory memory.


2. Efficient memory usage: Nodes in a singly linked list use less memory than nodes in a doubly linked list because they contain only a pointer to the next node and not to the previous one.


3. Easy implementation: Implementing a stack using a singly linked list is straightforward and can be done with minimal only code using just a few row lines.


4. Versatility: Singly linked lists can also be used to implement other data structures such as queues, other linked lists, and trees.

Author Information

Avatar
AuthorBeyza Nur TürküDecember 24, 2025 at 6:53 AM

Tags

Discussions

No Discussion Added Yet

Start discussion for "Heap Data Structure" article

View Discussions

Contents

  • LIFO (Last In, First Out) Principle

  • Types of Stacks

  • Basic Stack Operations

  • Advantages of Implementing a Stack Using a Linked List

Ask to Küre