| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 446 人关注过本帖
标题:[求助]菜鸟问题,关于数据结构的堆栈
只看楼主 加入收藏
小鸟向前飞
Rank: 1
等 级:新手上路
帖 子:72
专家分:0
注 册:2007-10-25
结帖率:100%
收藏
 问题点数:0 回复次数:0 
[求助]菜鸟问题,关于数据结构的堆栈

建一个简单的堆栈:
#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)

等回答,谢谢了~~


搜索更多相关主题的帖子: 堆栈 数据结构 int void 
2007-10-25 15:09
快速回复:[求助]菜鸟问题,关于数据结构的堆栈
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032001 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved