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

📄 实验三(1).cpp

📁 2007数据结构课程设计报告+源代码
💻 CPP
字号:
#include<iostream.h>
#define Maxlen 6
struct node{  
 int data;node *next;
 };
enum error_cord  { overflow, underflow, success};
int ru[6]={1,2,3,4,5,6};
int chu[6];
struct stack
{
public:
	stack();
	bool kong()const;
    bool mang() const;
	error_cord Getop(int &x)const	;
	error_cord Push(const int x);
	error_cord pop();
private:
	int count,n,s;
	node *p,*next,*Top;
};
stack::stack()
{
	count=0;
	Top=NULL;
}
bool stack::kong() const                              //判断是否为空 
{
	if(count==0)
	    return zhengque;
	else 
		return shibai;
}
bool stack::mang() const                                     //判断是否为满  
{
     return count==Maxlen;
}
error_cord stack::Getop(int &x)const                          //取顶元素 
{
		if (kong()) return underflow;
	     x=Top->data;
	     return success;
}
error_cord stack::Push(const int x)                           //进栈 
{
	if(mang())
		return overflow;
	node *s;
	s=new node; 
	s->data=x;
	s->next=Top;  
	Top=s;
	count++;
	return success;
}
error_cord stack::pop()                                            //删除元素 
{
	 if (kong()) return underflow; 
	 node *u;
	 u=Top; 
	 Top=Top->next; 
	 delete u;
	 count--; 
	 return success;
}
void judgetf()
{
	stack k;
	int b=0,c,e=0,d,zhe[6];
	for(int a=0;a<6;a++)
	{
		if(k.kong())
		{
			for(;b<8;)
			{
				k.Push(ru[b]);
				if(chu[a]!=ru[b])
					b++;
				else
				{
					b++;
					break;
				}
			}
		}
		else
		{
			k.Getop(d);
			if(chu[a]!=d)
			{
			   for(;b<8;)
			   {
				  k.Push(ru[b]);
				  if(chu[a]!=ru[b])
					  b++;
				  else
				  {
					b++;
					break;
				  }
			   }
			}
		}
		k.Getop(c);
		zhe[a]=c;
		k.pop();
		if(b>7)
			break;
	}
	for(int f=0;f<6;f++)
	{
		if(chu[f]==zhe[f])
			;
		else
		{
			e=1;break;
		}
	}
	if(e==0)
		cout<<"序列成功"<<endl;
	else
		cout<<"序列不成功"<<endl;
}
void main()
{
	int  b,d;
	cout<<"输出从1到6的整数数据的序列"<<endl;
	for(int c=0;c<5;c++)
	{
		cin>>d;
		chu[c]=d;
	}
	judgetf();
}

⌨️ 快捷键说明

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