badge icon

This article was automatically translated from the original Turkish version.

Article
Quote
datastructure.jpg

Stack

Data Structure Type

Linear

Basic Operations

push()

pop()

peek()

isEmpty()

isFull()

Application Area(s)

Artificial Intelligence and Automation Systems

Software Development and Programming Languages

Data Processing and Algorithms

Operating Systems

Game Development

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 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 implies, a fixed-size stack has a predetermined size and cannot grow or shrink dynamically. 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(): Adds an element to the stack.


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


  • pop(): Removes 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 pre-allocation of a fixed amount of 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. Simple implementation: Implementing a stack using a singly linked list is straightforward and can be done with just a few lines of code.


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

Bibliographies

GeeksforGeeks. "What is Stack Data Structure? A Complete Tutorial." (2024).Accessed Adresi.

Geeksforgeeks. "Applications, Advantages and Disadvantages of Stack." (2024).Accessed Adresi.

Geeksforgeeks. "Implement a Stack Using Singly Linked List." (2024).Accessed Adresi.

Programiz. "Stack Data Structure."

TpointTech. "What is a Stack?"

Tutorialspoint. "Stack Data Structure."

W3schools. "DSA Stacks."

Author Information

Avatar
AuthorBeyza Nur TürküJuly 14, 2026 at 4:53 PM

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