#include <stdio.h>
#include <stdlib.h>
//#define
typedef struct
{
int *base;
int *top;
int stacksize;
}stack;
#include <stdlib.h>
//#define
typedef struct
{
int *base;
int *top;
int stacksize;
}stack;
void initstack(stack *str)
{
str->base = (int*)malloc(sizeof(int)*100);
if(NULL == str->base)
{
printf("malloc failure\n");
}
str->top = str->base;
str->stacksize = 100;
{
str->base = (int*)malloc(sizeof(int)*100);
if(NULL == str->base)
{
printf("malloc failure\n");
}
str->top = str->base;
str->stacksize = 100;
}
void push(stack*str,int i)
{
if(str->top - str->base >= str->stacksize)
{
str->base = (int*)realloc(str->base,sizeof(int)*(str->stacksize + 10));
}
if(NULL == str->base)
{
printf("realloc fileure\n");
}
*str->top++ = i;
}
{
if(str->top - str->base >= str->stacksize)
{
str->base = (int*)realloc(str->base,sizeof(int)*(str->stacksize + 10));
}
if(NULL == str->base)
{
printf("realloc fileure\n");
}
*str->top++ = i;
}
int pop(stack*str)
{
if(str->base == str->top)
{
exit(-1);
}
else
{
return *--str->top;
{
if(str->base == str->top)
{
exit(-1);
}
else
{
return *--str->top;
}
}
int main()
{
int i;
}
int main()
{
int i;
stack str1;
stack str2;
stack str2;
initstack(&str1);
initstack(&str2);
initstack(&str2);
for(i = 1;i < 6;i++)
{
push(&str1,i);
printf("%3d",i);
}
{
push(&str1,i);
printf("%3d",i);
}
printf("\n");
while(str1.base != str1.top)
{
while(str1.top - str1.base > 1)
{
push(&str2,pop(&str1));
}
printf("%3d",pop(&str1));
while(str2.top - str2.base > 0)
{
push(&str1,pop(&str2));
}
}
return 0;
while(str1.base != str1.top)
{
while(str1.top - str1.base > 1)
{
push(&str2,pop(&str1));
}
printf("%3d",pop(&str1));
while(str2.top - str2.base > 0)
{
push(&str1,pop(&str2));
}
}
return 0;
}