Created
December 27, 2017 09:40
-
-
Save you74674/0e6633c1f0a4d4cdf62d9b7d1fa528e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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