建一个简单的堆栈:
#include<iostream.h>
#include <stdlib.h>
#include<malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW 0
#define OK
#define ERROR
typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;
void InitStack(SqStack &s);
void GetTop(SqStack &s,int e);
void Push(SqStack &s,int e);
void main()
{
for(int i=0;i<100;i++)
{
for(int m=0;m<100;m++)
int a[1] = 1;
}
push(SqStack &s,int a);
printf("%d""插入的栈为:");
}
void InitStack(SqStack &s)
{
s.base = (int *)malloc(STACK_INIT_SIZE *sizeof(int));
if(!s.base)
exit(OVERFLOW);
s.top = s.base;
s.stacksize = STACK_INIT_SIZE;
return OK;
}
void GetTop(SqStack &s,int e)
{
if(s.top == s.base)
return ERROR;
e = *(s.top - 1);
return OK;
}
void Push(SqStack &s,int e)
{
if(s.top - s.base>=s.stacksize)
{
s.base = (int *)realloc(s.base,(s.stacksize + STACKINCREMENT)*sizeof(int));
if(!s.base)
exit(OVERFLOW);
s.top = s.base + s.stacksize;
s.stacksize += STACKINCREMENT;
}
*s.top++ = e;
//printf ("插入的栈为:");
return OK;
}
报错:
--------------------Configuration: x - Win32 Debug--------------------
Compiling...
x.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(27) : error C2440: 'initializing' : cannot convert from 'const int' to 'int [1]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(29) : error C2065: 'push' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(29) : error C2065: 's' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(29) : error C2275: 'SqStack' : illegal use of this type as an expression
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(16) : see declaration of 'SqStack'
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(29) : error C2062: type 'int' unexpected
C:\Program Files\Microsoft Visual Studio\MyProjects\x\x.cpp(30) : error C2065: 'printf' : undeclared identifier
Error executing cl.exe.
x.exe - 6 error(s), 0 warning(s)
等回答,谢谢了~~