入栈和出栈|入栈与出栈的所有排列可能性

更新时间:2015-02-21    来源:淘宝规则    手机版     字体:

【www.bbyears.com--淘宝规则】


#include
#include
#include ios.h>
#include
#include
/*定义全局变量*/
int pu=0,po=0,t=0;
char tp[130][12];


/*用栈排出入栈出栈的顺序*/
struct train{
  int numb;
  struct train *next;
  };

struct push{
  int a;
  int b;
  char data[24];
  struct push *next;
  };

struct push *creat(struct push *top)
{
  top=(struct push *)malloc(sizeof(struct push));
  top->next=NULL;
  return top;
}

struct push *pup(struct push *top,int a,int b,int n)
{
  struct push *p,*q;
  q=top->next;
  p=(struct push *)malloc(sizeof(struct push));
  p->a=a;
  p->b=b;
  if(q)
    strcpy(p->data,q->data);
  if(q->a   {
    p->data[a+b-1]="r";
    p->data[a+b]="";
   }
  else
   {
     p->data[a+b-1]="c";
     p->data[a+b]="";
   }
  p->next=top->next;
  top->next=p;
return top;
}

struct push *pop(struct push *top)
{
  top=top->next;
  return top;
}

struct push *apaili(struct push *top,int numb)  /*向后移动一个出命令*/
{
  struct push *q;
  q=top->next;
  if(pu   {
     pu++;
     top=pup(top,pu,po,numb);
     top=apaili(top,numb);
    }

本文来源:http://www.bbyears.com/taobaodaxue/13118.html

猜你感兴趣

热门标签

更多>>

本类排行