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

📄 emp3_05.cpp

📁 该包是数据结构的实验软件,来源于合肥工业大学人工智能与数据挖掘实验室,用来实现数据结构.
💻 CPP
字号:
#include"sstack.h"
  SeqStack S;
   boolean   Valid_Element(bb1& A,int n)
    {  int   i;
      boolean ok;
      //ISet:set of 1..10;
	ok=true;  //ISet:=[];
	     for (i=1 ;i<=n;i++)
	       {
		 if  (A[i]<1||A[i]>n ) //||(A[i] in Iset)
		      ok=false ;
	       else     //ISet:=ISet+[A[i]];
		     ;
		}
      boolean     Valid_Element=ok;
      return Valid_Element;
      }


   boolean  judge_Stack_Sequence(bb1& A,int n)
      {int  i,j,x;
       boolean ok;
	i=1; j=1; ok=true;
	SeqStack_setnull(S);
	while  ( (i<=n)&& ok)
	{
	    while ( (SeqStack_empty(S)||(A[i]>SeqStack_top(S) ) )&& (j<=n) )
	       {  SeqStack_push(S,j); j=j+1;}
	    if (!SeqStack_empty(S)&&(SeqStack_top(S)==A[i]) )
		 { i=i+1;
		   SeqStack_pop(S,x);
		  }
	       else
		 ok=false;
	  }
      boolean	 judge_Stack_Sequence=ok;
      return judge_Stack_Sequence ;
    }

   main()
   {int  n;
     bb1 A;


     set_SeqStack(S,"Stack",1,9);
      do
      {
       window(1,1,80,25);
       gotoxy(5,4);
       string ss;
       Spaces(ss,20) ;
       cout<<ss<<endl;
       gotoxy(5,4);
       cout<<"n[0 to end]=";
       cin>>n;
       if (n<=0 )
	 exit(0);
	do
	  {
	  gotoxy(8,12);
	  cout<<"     Please input data into the array";
	   input_Arrbb(A,1,n);
	   if (! Valid_Element(A,n) )
		 Error("The Sequence is not valid, Input again ");
	   }
	while(!Valid_Element(A,n) );
	move_SeqStack_mid(S,getmaxx()/2,getmaxy()/2-80);
	if (judge_Stack_Sequence(A, n) )
	    Dispstrinwnd(20,4,"This sequence is Valid output of stack ");
	else
	    Dispstrinwnd(20,4,"This sequence is not valid output of stack ");
     }
     while(n!=0);
}

⌨️ 快捷键说明

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