Posts

Showing posts from July, 2015

Stack for storing character value using pointer

// stack using pointer for character array #include<stdio.h> #include<conio.h> typedef struct stack { int top; char ar[50]; }st; void push(st*,char); char pop(st*); char peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int ch; char m; st s; s.top=-1; while(1) { printf("\n\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); fflush(stdin); scanf("%c",&m); push(&s,m); } else printf("\nNo more space ..... "); break; case 2: if(!isempty(s)) { printf("\n\nThe popped value is %c",pop(&s)); } else printf("\nNothing to display ....."); break; case 3: if(!isempty(s)) { printf("\n\nThe top most value is %c",peek(s)); } else printf("\nNothing to display .....");...

Stack using structure pointer

#include<stdio.h> #include<conio.h> typedef struct stack { int top; int ar[50]; }st; void push(st*,int); int pop(st*); int peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int m,ch; st s; s.top=-1; while(1) { printf("\n\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); scanf("%d",&m); push(&s,m); } else printf("\nNo more space ..... "); break; case 2: if(!isempty(s)) { printf("\n\nThe popped value is %d",pop(&s)); } else printf("\nNothing to display ....."); break; case 3: if(!isempty(s)) { printf("\n\nThe top most value is %d",peek(s)); } else printf("\nNothing to display ....."); break; case 4: if(!isempty(s)) { printf("\n\nThe values are...

stack using structure

#include<stdio.h> #include<conio.h> typedef struct stack { int top; int ar[50]; }st; void push(st*,int); int pop(st*); int peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int m,ch; st s; s.top=-1; while(1) { printf("\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); scanf("%d",&m); push(&s,m); } else printf("No more space ..... "); break; case 2: if(!isempty(s)) { printf("The popped value is %d",pop(&s)); } else printf("Nothing to display ....."); break; case 3: if(!isempty(s)) { printf("The top most value is %d",peek(s)); } else printf("Nothing to display ....."); break; case 4: if(!isempty(s)) { printf("The values are"); disp(s); } ...