乞求大家看看这个顺序栈吧
//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;
}
这到底哪错了!!
#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;
}
这到底哪错了!!
...全文
相关推荐
顺序栈实现
在这个场景中,我们将探讨如何使用C++模板来创建一个顺序栈。首先,我们需要定义一个顺序栈类,它通常包含两个核心部分:存储元素的数组和指向栈顶的指针。
顺序栈的基本操作
通过以上内容,我们可以深入理解顺序栈的基本概念、数据结构以及如何在C语言中实现和操作顺序栈。在实际编程中,顺序栈广泛应用于递归、表达式求解、内存管理等多种场景,是学习数据结构和算法的基础。
顺序栈基本操作
在本篇文章中,我们将重点讨论顺序栈的实现与操作。### 二、顺序栈的操作#### 1.
C++模板实现顺序栈
C++模板实现顺序栈C++模板实现顺序栈是指使用C++语言中的模板(template)机制来实现顺序栈数据结构的存储和操作。顺序栈是一种常用的数据结构,用于存储和操作元素的集合。
顺序栈的各种基本操作
### 顺序栈的基本操作#### 一、顺序栈概述顺序栈是一种基于顺序存储结构的栈,它通过数组来实现栈的功能。与链式栈不同,顺序栈中的元素是连续存储的,通常需要预分配一定的空间来存放栈中的元素。


