回 帖 发 新 帖 刷新版面

主题:求救,用栈和队列进行回文判断,有好多错误,谁帮忙看一下

#include<stdio.h>
#define ok 1
#define error 0
#define stack_size 50
typedef struct            //定义顺序栈
{  char elem[stack_size];
   int  top;
}seqstack;
typedef struct node        //定义链队列
{  char date;
   struct node *next;
}linkqueuenode;
typedef struct
{  linkqueuenode *front;
   linkqueuenode *rear;
}linkqueue;
void initstack(seqstack *s)     //初始化顺序栈
{  s->top=-1;
}
void push(seqstack *s,char x)     //进栈
{  if(s->top==stack_size-1)
   printf("栈已满");
   else
{
   s->top++;
   s->elem[s->top]=x;
}
}
void pop(seqstack *s,char*x)   //出栈
{  if(s->top==-1)
   printf("栈为空");
   else
   {   *x=s->elem[s->top];
       s->top--;
   }
}
void initqueue(linkqueue *q)      //初始化队列
{   q->front=(linkqueuenode *)malloc(sizeof(linkqueuenode));
    if(q->front!=null)
    {   q->rear=q->front;
        q->front->next=null;
    }
    else 
      printf("链队列溢出");
}
void enterqueue(linkqueue * q,char x)     //入队
{    linkqueuenode * s;
     s=(linlqueuenode*)malloc(sizeof(linlqueuenode));
     if(s!=null)
     {  s->date=x;
        s->next=null;
        q->rear->next=s;
        q->rear=s;
     }
     else 
    printf("链队列溢出");
}
void deletequeue(linkqueue *q,char *x)    //出队
{     linkqueue *p;  
      if(q->front==q->rear)
         printf("对为空");
      p=q->front->next;
      q->front->next=p->next;
      if(q->rear==p)
          q->rear=q->front;
      *x=p->date;
       //free(p);
      
}

void main()
{     seqstack l;
      linkqueue y;
      char ch1,ch2,ch;
      int  m=0,i;
      initstack(&l);
      initqueue(&y);
      printf("请输入一串字符(以@结尾):");
      ch=getchar();
      while(ch!='@')
      {   ch=getchar();
          if(ch!='@')
          {push(&l,ch);
          enterqueue(&y,ch);
          m++;
          }
      }
      if(m%2!=0)
      {   
          if(l->elem[m/2]=='&')
          {  
              for(i=1;i<m/2;i++)
              {   pop(&l,&ch1);
                  deletequeue(&y,&ch2);
                  if(ch1!=ch2)
                      printf("不是回文序列");
                  else
                     printf("不是回文序列");
              }
          }
           else
                     printf("不是回文序列");
          
      }
}

回复列表 (共1个回复)

沙发


Facebook短期入华, “联姻百度”或是虚晃

近日,作为全球最为风行的SNS网站,Facebook(脸谱)再度吸引了国际网民眼球,由于被DCCI互联网数据中心总经理胡延平爆出入华协议曾经正式签署,落地协作方为国际某网站,并将采取另建新站的落地形式,给不少网民带来了不少遥想的空间。

不过,...全文请点击

[url=http://www.dotnetsz.com/Html/News/201104/2044.html]http://www.dotnetsz.com/Html/News/201104/2044.html[/url]

我来回复

您尚未登录,请登录后再回复。点此登录或注册