第三章

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
const int StackSize=100;
template
class SeqStack
{
public:
SeqStack ( ){top=-1; } ;
~SeqStack ( );
void Push ( T x );
T Pop ( );
T GetTop ( ) {if (top!=-1) return data[top];}
bool Empty ( )
{
if(top

void Push( T x );

template
void SeqStack::Push ( T x)
{
if (topStackSize-1) throw “溢出”;
top++;
data[top]=x;
}
T Pop( );
template
T SeqStack:: Pop ( )
{
if (top
-1) throw “溢出”;
x=data[top–];
return x;
}
const int StackSize=100;
template
class BothStack
{
public:
BothStack( ) {top1= -1; top2=StackSize;}
~BothStack( );
void Push
(int i, T x
);
T Pop
(int i
);
T GetTop
(int i
);
bool Empty
(
void Push(int i, T x) ;
template
void BothStack::Push(int i, T x )
{
if (top1top2-1) throw “上溢”;
if (i
1) data[++top1]=x;
if (i2) data[–top2]=x;
}
template
T BothStack::GetTop(int i)
{
if(i
1)
{ if (top1!=-1) return data[top1]; }
if(i2)
{ if(top2!=StackSize) return data[top2]; }
}
bool Empty(int i) ;
bool Empty(int i) ;
template
class LinkStack
{
public:
LinkStack(){top=NULL; }
~LinkStack( );
void Push(T x);
T Pop( );
T GetTop( ){if(top!=NULL)return top->data; }
bool Empty ( ){return(top
NULL? 1: 0); }
p
const int QueueSize=100;
template
class CirQueue
{
public:
CirQueue( ){front=rear=QueueSize-1;}
~ CirQueue( );
void EnQueue(T x);
T DeQueue( );
T GetQueue( );
bool Empty( ){return(frontrear? 1: 0);}
private:
T data[QueueSize];
int front, rear;
};
template
class LinkQueue
{
public:
LinkQueue( );
~LinkQueue( );
void EnQueue(T x);
T DeQueue( );
T GetQueue( );
int Empty( ){return(front
rear?1:0);}
private:
Node *front, *rear;
};
template
LinkQueue::LinkQueue( )
{
front=new Node;
front->next=NULL;
rear=front;
}
template
void LinkQueue::EnQueue(T x)
{
s=new Node;
s->data=x;
s->next=NULL;
rear->next=s;
rear=s;
}
template
T LinkQueue::DeQueue( )
{
if (rearfront) throw “下溢”;
p=front->next;
x=p->data;
front->next=p->next;
if (p->next
NULL) rear=front;
delete p;
return x;
}

void conversion (int N,int d) {
SeqStack S; // 构造空栈
int e;
while (N) {
S.Push(N % d); // "余数"入栈
N = N/d;//非零商继续运算
}
while (!S.Empty()) {// 和"求余"所得相逆的顺序输出d进制的各位数
e=S.Pop();
cout<<e;
}
} // conversi
bool matching(char exp[]) {
// 检验表达式中所含括号是否正确嵌套,
//若是,则返回TRUE,否则返回FALSE. ‘#’ 为表达式的结束符
int state = 1,i=0;
char ch,e;
ch = exp[i++];
SeqStack S; // 构造空栈
while (ch!=’\0’ && state) {
if(ch==’(’ || c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值