⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实验三(3).cpp

📁 2007数据结构课程设计报告+源代码
💻 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 + -