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

📄 实验三(4).cpp

📁 2007数据结构课程设计报告+源代码
💻 CPP
字号:
#include "iostream.h"
#include "string.h"
#define maxlen 99
class stack
{
public:
	stack();
	bool kongde();
	void Pust(int x);
    int POP();
private:	
	int count;
	int data[maxlen];
};
stack::stack()
{
	count=0;
}
bool stack::kongde()
{
	return (count==0);
}
 void  stack::Pust(int x)
 {
	 data[count]=x;
	 count++;
 }	
int  stack::POP()
{
	count--;
	return data[count];
}
void p11(int w)
{
	stack s;
	int array[30];
	int j=0;
	int f[10]={0,0};
	int i=2;
	for(i;i<10;i++)
		f[i]=f[i-2]+f[i-1]+i-1;
	while(w>0||!s.kongde())
	{
		while(w>0)
		{
			s.Pust(w);
		array[j++]=w;
			w=w-2;
		}
		if(!s.kongde())
		{
			w=s.POP();
			w=w-1;
		}

	}
		for(i=j-1;i>=0;i--)
		cout<<array[i]<<","<<f[array[i]+1]<<endl;

}
void main()
{
	p11(7);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -