#include<stdio.h> #include<stdlib.h> #include<conio.h> struct node { int data; struct node *link; }; struct node *top=NULL,*temp; void main() { int choice,data; clrscr(); while(1)//infinite loop is used to insert/delete infinite number of nodes { printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n"); printf("\nEnter ur choice:"); scanf("%d",&choice); switch(choice) { case 1: temp=(struct node *)malloc(sizeof(struct node)); printf("Enter a node data :"); scanf("%d",&data); temp->data=data; temp->link=top; top=temp; break; case 2: if(top!=NULL) { printf("The poped element is %d",top->data); top=top->link; } else { printf("\nStack Underflow"); } break; case 3: temp=top; if(temp==NULL) { printf("\nStack is empty\n"); } while(temp!=NULL) { printf("->%d->",temp->data); temp=temp->link; } break; case 4: exit(0); } } }
A collection of example source codes for c/c++ and ios and android platform. It also includes objective c.
Showing posts with label Stack implementation. Show all posts
Showing posts with label Stack implementation. Show all posts
Tuesday, May 10, 2011
A C++ Stack implementation using Linked List.
An example C++ implementation of Stack data structure using Linked List.
Subscribe to:
Posts (Atom)