Stack Implementation in C

This C program actually simulates the stack operations graphically and in text mode. User can Add, Delete, Search, and Replace the elements from the stack. It also checks for Overflow/Underflow and returns user friendly errors. You can use this stack implementation to perform many useful functions. In graphical mode, this C program displays a startup message and a nice graphic to welcome the user.

The program performs the following functions and operations:

  1. Add: Pushes an element to the stack. It takes an integer element as argument. If the stack is full then error is returned.
  2. Delete: Pop an element from the stack. If the stack is empty then error is returned. Th element is deleted from the top of the stack.
  3. Search: This function takes an integer element as an argument and returns the location on the element. If number is not found then 0 is returned.
  4. Replace: This function takes two integers as arguments, first number is to find and second is to replace with. It first performs the search operation the replaces the integers.

This software is provided by MYCPLSU with the source code, you are free to use this code as you need and change the code.

  Stack Implementation in C (79.2 KiB, 13,743 hits)

Stack implementation in text mode

Stack implementation in text mode

Stack Implementation in graphical mode

Stack Implementation in graphical mode

7 Comments

  1. a single-linked list is used to implement a stack. the first element of the linked list is the top of the stack.The second element of the linked list is the one next to the top in the stack, etc. The last record (stack bottom) always points to NULL. a pointer to the stack has the value NULL when the stack is empty.suppose that the structure o a stack is defined a follows:

    In C code, complete the definition of the function POPALL that will pop all the elements of astack, freeing the memory occupied by the stack for future re-use.

Leave a Reply