早教吧作业答案频道 -->其他-->
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滴练习的定义部...的网友还看了以下:
可以参考的公式是:s[1]=a[1];s[n]=s[n-1]>=0?s[n-1]+a[n]:a[n 2020-05-14 …
定义y=log(1+x)F(x,y),x、y∈(0,+∞),(Ⅰ)令函数f(x)=F(x,2)-3 2020-05-14 …
PI的 初始值为什么是pi=1#includemain(){int s;float n,t,pi; 2020-05-16 …
1.对每个正整数n,用S(n)表示n的各位数字之和,那么有()个n使得n+S(n)+S(S(n)) 2020-05-21 …
若该图表示上半年a、b两月(a月早于b月).则①、②、③、④四地纬度依次是()A.665°N、66 2020-06-23 …
若准线方程是f(x,y)=0,z=0,当母线的方向向量是S={L,m,n}时,柱面方程为f(x-L 2020-07-09 …
已知数列{a[n]}的前n项和为S[n],且满足a[n]+2S[n]×S[n-1]=0(n≥0),a 2020-11-01 …
C程序中,对的数组有1.合法的数组定义是()。A.chara[]={‘s’,‘t’,‘r’,‘i’, 2020-12-05 …
(1)算法,第一步.(1)算法:第一步,赋值变量S=0,n=0,i=0第二步,计算i+1,仍用i表示 2020-12-09 …
执行下列语句后,s的值是?intn=5,s=0;while(n)s+=n--S的值为执行下列语句后, 2020-12-15 …