乞求大家看看这个顺序栈吧

lrd408 lrd408 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//lrd.h
#ifndef LRD_H
#define LRD_H
#define NUM 10
#include <iostream>

class tack {
public:
double* stase;
double* top;
int sizeoftack;

tack(double* stase,double* top,int sizeoftack);
~tack();
}
#endif

//aa.h
#ifndef AA_H
#define AA_H
#include <iostream>
#include "lrd.h"
using std::cout;
using std::endl;



//得到一个栈的头元素
double GetTop(const tack& S) {
double e=0.0;
if(S.stase-S.top==0)
{if(S.stase==0)
cout<<"这是一个空栈!!!"<<endl;}
else e=*(S.top-1);
return e;
}

//压入栈
tack* Push(tack* T,double e) {
*(*T).top++ =e;
return T;
}

//删除栈
double Pop(tack* T) {
double e=0.0;
e= * --(*T).top;
delete (*T).(top+1);//我想删了top的上一个元素

return e;
}
#endif

//lrd.cpp
#include <iostream>
#include "lrd.h"

tack::tack(double* stase,double* top,int sizeoftack) {
stase=new double[NUM*sizeof(double)];
top=stase;
sizeoftack=NUM;
}

tack::~tack () {
delete [] stase;
delete [] top;
}

//main.cpp
#include <iostream>
#include <iomanip>
#include "lrd.h"
#include "aa.h"
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;

int main() {
tack we;
tack* p=&we;
double ab[10]={12.36,56.23,78.25,89.123,45.789,58.369,1.2,3.6};
if(!we.stase) exit(1);
for(int i=0;i<=10;i++)
Push(p,ab[i]);
cout<<setprecision(8)<<fixed;
do{ i=0;i++;
cout<<Pop(p);
if(i%5==0) cout<<'\n';
else cout<<" ";
}while((*p).top==(*p).stase);

return 0;
}

这到底哪错了!!



...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
lrd408
C++ 语言 65,214 成员 250,514 内容