?? 實(shí)驗(yàn)三(1).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) //進(jìn)棧
{
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的整數(shù)數(shù)據(jù)的序列"<<endl;
for(int c=0;c<5;c++)
{
cin>>d;
chu[c]=d;
}
judgetf();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -