?? 實驗三(3).cpp
字號:
#include<iostream.h>
struct node
{
int data; node *next;
};
enum error_code {success,underflow,overflow};
class stack
{
public:
stack();
~stack();
bool kongde()const;
error_code get_Top(int &x)const;
error_code Push(const int x);
error_code Pop();
private:
int count;
node *Top;
};
stack::stack()
{
count=0;
Top=NULL;
}
stack::~stack()
{
while(!kongde())
Pop();
}
bool stack::kongde()const
{
return count==0;
}
error_code stack::get_Top(int &x)const
{
if(kongde()) return underflow;
else
x=Top->data;
return success;
}
error_code stack::Push(const int x)
{
node *s=new node;
s->data=x;
s->next=Top;
Top=s;
count++;
return success;
}
error_code stack::Pop()
{
if(kongde())
return underflow;
else
{
node *u=Top;
Top=Top->next;
delete u;
count--;
return success;
}
}
/*void p(int w)
{
if(w>0)
{cout<<w;
p(w-1);
p(w-1);
}
}*/
void p(int i)
{
stack s;
while(i>0||!s.kongde())
{
while(i>0)
{
s.Push(i);
i=i-1;
}
if(!s.kongde())
{s.get_Top(i);s.Pop();cout<<i;i=i-1;}
}
}
void main()
{
p(5);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -