Posts

Showing posts from November, 2015

Stack Using Linked List in C

#include<stdio.h> #include<conio.h> typedef struct StackLinked { int val; struct StackLinked *next; }sl; sl *push(sl *,int); int pop(sl **); int peek(sl *); int isempty(sl *); void disp(sl *); void main() { sl *top=NULL; int ch,v; while(1) { printf("\n\n1) Push\n\n2) Pop\n\n3) Peek\n\n4) Display\n\n5) Exit"); printf("\n Enter your choice :"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter the number you want to push : "); scanf("%d",&v); top=push(top,v); break; case 2:  if(!isempty(top))   {   printf("\n\nYou have popped %d",pop(&top));   }   else   printf("\n\nNothing to pop"); break; case 3: if(!isempty(top))   {   printf("\n\nTop most value is %d",peek(top));   }   else   printf("\nNothing in the stack"); break; case 4: if(!isempty(top))   {   printf("\n\nValues in th