Open links in new tab
  1. Stack Data Structure and Implementation in Python, Java and C/…

    Learn how to create and use a stack, a linear data structure that follows the LIFO principle. See the basic operations of push, pop, isEmpty, isFull, and peek, and how to …

    Programiz
    DSA Stacks - W3Schools

    Learn how to implement stacks using arrays or linked lists in Python. Stacks are data structures that follow the LIFO (last in first out) principle and can be used for various algorithms.

    W3School
    Stack using array - Codewhoop

    Lets take an example of an array of 5 elements to implement stack.

    https://www.codewhoop.com/stack/stack-using-array.html
  1. A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. Below is a C program to implement a stack using an array, supporting push, pop, and display operations.

    Code Example

    #include <stdio.h>
    #include <stdlib.h>

    #define MAX 5 // Maximum size of the stack

    int stack[MAX];
    int top = -1; // Initialize stack as empty

    // Function prototypes
    void push();
    void pop();
    void display();

    int main() {
    int choice;

    while (1) {
    printf("\n*** Stack Menu ***\n");
    printf("1. Push\n");
    printf("2. Pop\n");
    printf("3. Display\n");
    printf("4. Exit\n");
    printf("Enter your choice: ");
    scanf("%d", &choice);

    switch (choice) {
    case 1:
    push();
    break;
    case 2:
    pop();
    break;
    case 3:
    display();
    break;
    case 4:
    exit(0);
    default:
    printf("Invalid choice! Please try again.\n");
    }
    }
    return 0;
    }

    // Function to push an element onto the stack
    void push() {
    int val;

    if (top == MAX - 1) {
    printf("Stack Overflow! Cannot add more elements.\n");
    } else {
    printf("Enter the element to push: ");
    scanf("%d", &val);
    stack[++top] = val;
    printf("Element pushed: %d\n", val);
    }
    }

    // Function to pop an element from the stack
    void pop() {
    if (top == -1) {
    printf("Stack Underflow! The stack is empty.\n");
    } else {
    printf("Element popped: %d\n", stack[top--]);
    }
    }

    // Function to display the elements of the stack
    void display() {
    if (top == -1) {
    printf("Stack is empty!\n");
    } else {
    printf("Stack elements:\n");
    for (int i = top; i >= 0; i--) {
    printf("%d\n", stack[i]);
    }
    }
    }
    Copied!
    Feedback
  2. Build an Array With Stack Operations - LeetCode

    Build an Array With Stack Operations - You are given an integer array target and an integer n. You have an empty stack with the two following operations: * "Push": pushes an integer to the top of the stack. * …

  3. Implement Stack Using Array (C, C++, Java, and Python)

    Feb 13, 2026 · Learn how to implement a stack using an array in C, C++, Java, and Python in this step-by-step tutorial to master this essential data structure technique.

  4. Stack Implementation Using Array in C - W3Schools

    This tutorial explains implementing a basic stack data structure in C using an array. It covers the push and pop operations and error handling for stack overflow and underflow.

  5. Stack Data Structure and Implementation in Python, …

    Learn how to create and use a stack, a linear data structure that follows the LIFO principle. See the basic operations of push, pop, isEmpty, isFull, and peek, and …

  6. DSA Stacks - W3Schools

    Learn how to implement stacks using arrays or linked lists in Python. Stacks are data structures that follow the LIFO (last in first out) principle and can be used …

  7. Stack Using Array - Problem - Online Tutorials Library

    Master Stack Using Array with solutions in 6 languages. Learn LIFO operations, push/pop implementation, and optimal O (1) algorithms.

  8. Stack Implementation Using Array in Data Structures

    Mar 5, 2026 · Learn how to implement stack using array, a linear data structure that follows the LIFO principle. See the algorithms and code for push, pop and peek …

  9. A Guide on Array-Based Stack Implementation - upGrad

    Jan 29, 2025 · Learn how to implement stacks using arrays in data structures. Discover the applications of stacks and its types. Also, learn about the benefits and drawbacks of the implementation and …

  10. Stack using array - Codewhoop

    Lets take an example of an array of 5 elements to implement stack.