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

📄 key04_4.cpp

📁 该包是数据结构的实验软件,来源于合肥工业大学人工智能与数据挖掘实验室,用来实现数据结构.
💻 CPP
字号:
//{test04_4}
#include"tools.h"
  const int maxsize=20;
  struct stack_element
	{int  ww,ff,ff1,ff2,ll;
	 };
      struct stack
	 { stack_element data[maxsize] ;
	   int top;
       };
  stack s;
  int A=0;
  void   Setnull(stack& s )
   { s.top=0;}
  boolean Empty(stack& s)
    {
    boolean Empty=s.top==0;
    return Empty ;
    }
  void   Push(stack& s,int w,int f,int f1,int f2,int l)
    {
       if (s.top==maxsize-1)
	 Error("Overflow");
       else
	   {
	   s.top=s.top+1;
	   s.data[s.top].ww=w;
	   s.data[s.top].ff=f;
	   s.data[s.top].ff1=f1;
	   s.data[s.top].ff2=f2;
	   s.data[s.top].ll=l;
	   }
  }
  void   Pop(stack& s,int& w,int& f,int& f1,int& f2,int& l)
    {
       if (s.top==0)
	 Error("Down Overflow of stack ");
       else
	 {
	     w=s.data[s.top].ww;
	     f=s.data[s.top].ff;
	     f1=s.data[s.top].ff1;
	     f2=s.data[s.top].ff2;
	     l=s.data[s.top].ll;
	     s.top=s.top-1;
	  }
   }
  void  P11(int w, int&  f)
   {int f1,f2;

       if (w<=0 )
	  f=0;
       else
	  {
	   P11(w-2,f1);
	   P11(w-2,f2);
	   f=f1+f2+w;
	   cout<<" ("<<w<<","<<f<<") ";
	  }
 }
  void P12(int w,int& f)
   { //label L0,L1,L2;
    int  backvar, labx,f1,f2;
      Setnull(s);
      L0:  if (w<=0)
	     f=0;
	  else
	    {
	    Push(s,w,f,f1,f2,1);    //   { for P11(w-2,f1) }
	    w=w-2;
	    f=f1;
	   goto L0;
      L1:   f1=backvar;
	    Push(s,w,f,f1,f2,2);    //   { for P11(w-2,f2) }
	    w=w-2;
	    f=f2;
	   goto L0;
      L2:   f2=backvar;
	    f=f1+f2+w;
	    cout<<" ("<<w<<","<<f<<") ";
	     }
	  if (!Empty(s) )
	    {  backvar=f;
	       Pop(s,w,f,f1,f2,labx);
	       if (labx==1)
		 goto L1 ;
		else
		  goto L2;
	    }
      }

  void  P13(int w,int& f)
   {int  backvar, labx,f1,f2;
      Setnull(s);
       do
	  {
	  while (w>0)
	     {
	     Push(s,w,f,f1,f2,1);
	     w=w-2;
	     f=f1;
	     }
	  f=0;
	  do
	     if (!Empty(s) )
	       {
	         backvar=f;
	         Pop(s,w,f,f1,f2,labx);
	         if (labx==2)
		     {
		      f2=backvar;
		       f=f1+f2+w;
		       cout<<" ("<<w<<","<<f<<") ";
		      }

	        }
	   while(!(Empty(s)||labx==1) );
	  if (labx==1)
	     { f1=backvar;
	       Push(s,w,f,f1,f2,2);
	       w=w-2;
	       f=f2;
	       }
      }
       while(!Empty(s));
    }

  main()
  {Into_graph();
  P11(7,A);
  cout<<endl;
  P12(7,A);
   cout<<endl;
  P13(7,A);
   cout<<endl;
   getch();
  }

⌨️ 快捷键说明

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