69,373
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define sizezifu 50000
#define new_size 50
typedef struct{
char **top;
char **base;
int size_top_base;
}zifu;
void init_zifu(zifu *s)
{
s->base = (char **)malloc(sizeof(char*)*new_size);
if(!(*(s->base)))
exit(-1);
*(s->top) = *(s->base);
s->size_top_base = 0;
}
void push(zifu *s,char *st_r1)
{
s->top[s->size_top_base] = (char *)malloc(sizeof(char) * sizezifu);
strcpy(s->top[s->size_top_base],st_r1);
s->size_top_base += 1;
}
void pop(zifu *s)
{
for(int i = 0;i < s->size_top_base;i++)
{
printf("%s\n",s->top[i]);
}
}
int main(void)
{
char st_r[20];
zifu *s;
init_zifu(s);
while(scanf("%s",st_r) != EOF)
{
char st_r1[300];
switch(st_r[0])
{
case 'E':
scanf("%s",st_r1);
push(s,st_r1);
break;
case 'B':
s->size_top_base -= 1;
break;
case 'F':
s->size_top_base += 1;
break;
case 'Q':
pop(s);
}
}
return 0;
}