Skip to content

Instantly share code, notes, and snippets.

@you74674
Created December 27, 2017 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save you74674/0e6633c1f0a4d4cdf62d9b7d1fa528e1 to your computer and use it in GitHub Desktop.
Save you74674/0e6633c1f0a4d4cdf62d9b7d1fa528e1 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"stack.h"
void init_class(stack *S)
{
(*S).a=(int*)malloc(100*sizeof(int));
(*S).len=0;
(*S).top=_top;
(*S).pop=_pop;
(*S).push=_push;
(*S).print=_print;
}
int main()
{
stack S;
init_class(&S);
char command[10];
while(scanf("%s", command)!=EOF)
{
if(strcmp(command, "push")==0)
{
int n;
scanf("%d", &n);
S.push(&S, n);
}
else if(strcmp(command, "pop")==0)
S.pop(&S);
else if(strcmp(command, "top")==0)
printf("%d\n", S.top(&S));
else if(strcmp(command, "print")==0)
S.print(&S);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment