|

楼主 |
发表于 2014-3-8 14:04:54
|
显示全部楼层
oggplay 发表于 2014-3-7 19:58
估计你的要求的地址范围超过windows系统的允许界限了
请看一下全代码:
#include <stdio.h>
#include <stdlib.h>
#define STACK_INITSIZE 100
#define STACK_ADDSIZE 10
typedef int LX;
typedef struct
{
LX *bottom;
LX *top;
int stack_size;
}stack;
void initstack(stack *s)
{
s->bottom=(LX *)malloc(STACK_INITSIZE * sizeof(LX));
if(!s->bottom)
exit(0);
s->top=s->bottom;
s->stack_size=STACK_INITSIZE;
}
void push(stack *s,LX *e)
{
if((s->top-s->bottom)>=s->stack_size)
{
s->bottom=(LX *)realloc(s->bottom,(s->stack_size+STACK_ADDSIZE)*sizeof(LX));
if(!s->bottom)
exit(0);
s->top=s->bottom+s->stack_size;
s->stack_size=s->stack_size+STACK_ADDSIZE;
}
(*s->top)=*e;
s->top++;
}
void pop(stack *s,LX *e)
{
if(s->top==s->top)
return;
*e=*--(s->top);
}
int main()
{
stack *s;
int i;
int a[100]={0},b[100]={1,2,3,4,5,6,7,8,9,10};
initstack(s);
push(s,b);
pop(s,a);
for(i=0;i<5;i++)
{
printf("%d ",a[i]);
}
return 0;
}
|
|