Oct 11, 2011

C Program to implement STACK operations using Linked Lists

Data structures using C, Stack is a data structure in which the objects are arranged in a non linear order. In stack, elements are aded or deleted from only one end, i.e. top of the stack. In this program, we implement the stack operations using linked list. Read more about C Programming Language .
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*                                  Happy Coding

#include <stdlib.h>
typedef struct node {
 int data;
 struct node *link;

void Push(int);
int pop();
void Display();
NODE *top = NULL; /* Global Declarations */

main() {
 /* Main Program */
 int opn, elem;
 do {
  printf("\n ### Linked List Implementation of STACK Operations ### \n\n");
  printf("\n Press 1-Push, 2-Pop, 3-Display,4-Exit\n");
  printf("\n Your option ? ");
  scanf("%d", &opn);
  switch (opn) {
  case 1:
   printf("\n\nRead the Element tobe pushed ?");
   scanf("%d", &elem);
  case 2:
   elem = Pop();
   if (elem != -1)
    printf(" Deleted Node(From Top)with the Data: %d\n", elem);
  case 3:
   printf("Linked List Implementation of Stack: Status:\n");
  case 4:
   printf("\n\n Terminating \n\n");
   printf("\n\nInvalid Option !!! Try Again !! \n\n");
  printf("\n\n\n\n  Press a Key to Continue . . . ");
 } while (opn != 4);

void Push(int info) {
 NODE *temp;
 temp = (NODE *) malloc(sizeof(NODE));
 if (temp == NULL)
  printf(" Out of Memory !! Overflow !!!");
 else {
  temp->data = info;
  temp->link = top;
  top = temp;
  printf(" Node has been inserted at Top(Front) Successfully !!");

int Pop() {
 int info;
 NODE *t;
 if (top == NULL) {
  printf(" Underflow!!!");
  return -1;
 } else {
  t = top;
  info = top->data;
  top = top->link;
  t->link = NULL;
  return (info);

void Display() {
 NODE *t;
 if (top == NULL)
  printf("Empty Stack\n");
 else {
  t = top;
  while (t) {
   printf("[%d]->", t->data);
   t = t->link;
Read more Similar C Programs
Data Structures

Learn C Programming
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
To browse more C Programs visit this link