Skip to content

Instantly share code, notes, and snippets.

@whalehulk
Last active September 11, 2017 11:01
Show Gist options
  • Save whalehulk/ee6aae6fc6eb19afbbc6920f5da7eae2 to your computer and use it in GitHub Desktop.
Save whalehulk/ee6aae6fc6eb19afbbc6920f5da7eae2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define max 10
//defining basic requirements like array for stack implementation
//top pointer or handler
//x to get the value that is to be pushed to the stack
int s[max],top=-1,x;
//making a push function for pushing x to the array
void push(void)
{
//checking overflow condition in the stack
if(top>=max)
{
printf("Error:Hey We Are Running Out Of Space");
}
//incrementing the pointer
top++;
s[top]=x;
printf("hey i just pushed %d to position %d",x,top);
}
void scan()
{
//scanning the element that has to be pushed to the stack
printf("Hey Enter The Element To Be Pushed To The Stack\n");
scanf("%d",&x);
push();
}
void pop(void)
{
//checking underflow condition
if(top==-1)
{
printf("\n error:stack underflow so nothing to delete \n");
}
//decrementing the position of the top pointer
top--;
printf("\n I just pushed off %d from the stack\n",s[top+1]);
}
int main()
{
//calling the functions
scan();
pop();
//so we have to implement stack .
//returning 0 as our main functions return type is an integer
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment