早教吧作业答案频道 -->其他-->
C的Stack滴练习的定义部分,那位帮忙纠错#include"stdio.h"#include"stdlib.h"#defineStackInitSize100#defineStackIncrement10#defineintint#defineOVERFLOW255//Stack类型
题目详情
C的Stack滴练习的定义部分,那位帮忙纠错
#include "stdio.h"
#include "stdlib.h"
#define Stack_Init_Size 100
#define StackIncrement 10
#define int int
#define OVERFLOW 255
//Stack类型
#include "stdio.h"
#include "stdlib.h"
#define Stack_Init_Size 100
#define StackIncrement 10
#define int int
#define OVERFLOW 255
//Stack类型
▼优质解答
答案和解析
你对指针和引用操作看来挺混乱的
指针使用元素时,要用->来连接
int InitStack(SqStack *s) //这里定义s是指针
{
s->base=(int*)malloc(Stack_Init_Size * sizeof (int)); //不能s.base,下同
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=Stack_Init_Size; //这个是对的
return 0;
}
引用时,如果原变量不是指针,就要用.(点)来连接 若是指针就用->来连接.
以下帮你修改好了
int InitStack(SqStack *s) //这里定义s是指针
{
s->base=(int*)malloc(Stack_Init_Size * sizeof (int)); //不能s.base,下同
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=Stack_Init_Size; //这个是对的
return 0;
}
int 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;
return 0;
}
int Pop(SqStack *s,int *e){
if(s->top == s->base) return 1;
e = --s->top;
return 0;
}
int StackEmpty(SqStack *s){
if(s->top - s->base
指针使用元素时,要用->来连接
int InitStack(SqStack *s) //这里定义s是指针
{
s->base=(int*)malloc(Stack_Init_Size * sizeof (int)); //不能s.base,下同
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=Stack_Init_Size; //这个是对的
return 0;
}
引用时,如果原变量不是指针,就要用.(点)来连接 若是指针就用->来连接.
以下帮你修改好了
int InitStack(SqStack *s) //这里定义s是指针
{
s->base=(int*)malloc(Stack_Init_Size * sizeof (int)); //不能s.base,下同
if(!s->base) exit(OVERFLOW);
s->top=s->base;
s->stacksize=Stack_Init_Size; //这个是对的
return 0;
}
int 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;
return 0;
}
int Pop(SqStack *s,int *e){
if(s->top == s->base) return 1;
e = --s->top;
return 0;
}
int StackEmpty(SqStack *s){
if(s->top - s->base
看了 C的Stack滴练习的定义部...的网友还看了以下:
谁用英语的每个英标组个单词.(意思是单词里面含有英标的音就好了)!全部的英标48个英语国际音标表2 2020-04-27 …
设A为n阶矩阵,证明:R(A+I)+R(A-I)>=n已知R(A)=R(kA),k≠0;R(A+B 2020-05-14 …
If I hadn"t stood under the ladder to catch you w 2020-05-14 …
Why do you work yourself so hard? I don’t do it _ 2020-05-16 …
用不同的方式表示“I don't want to set down a series of fac 2020-05-17 …
[p][b][m][w][h][i:][i][t][d][n]辅音字母每个要3个单词 2020-05-23 …
r=x(t)i+y(t)j+z(t)k详解本人刚初二,对于三维空间什么的没有学过,还有那括号里的t 2020-06-14 …
已知集合S={z||z-1|小于等于3,z属于C},T={z|z=(w+2)i/3=t,w属于S, 2020-08-02 …
一道挺难的数学题i*i=-1则x*x=-1可变为x=+i或-ii还具有以下性质:i=ii*i=-1i 2020-11-01 …
已知质点运动方程为r(t)=x(t)i+y(t)j其中x(t)=(m/s)t+2m,y(t)=(1/ 2020-11-01 …