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

📄 3.31.c

📁 部分高校使用anyview编程测试数据结构习题,此代码为数据结构题集(c语言版)严蔚敏版的课后习题答案.专门提供给在anyview上运行,全部为通告代码
💻 C
字号:
◆3.31③  假设称正读和反读都相同的字符序列为
"回文",例如,'abba'和'abcba'是回文,'abcde' 
和'ababab'则不是回文。试写一个算法判别读入的
一个以'@'为结束符的字符序列是否是"回文"。

实现下列函数:
Status Palindrome(char *word);
/* 利用栈和队列判定字符序列word是否是回文 */

可使用栈Stack和队列Queue及其下列操作:
Status InitStack(Stack &S);           
Status Push(Stack &S, ElemType x);    
Status Pop(Stack &S, ElemType &x);    
Status StackEmpty(Stack S);           

Status InitQueue(Queue &Q);
Status EnQueue(Queue &Q, ElemType x);
Status DeQueue(Queue &Q, ElemType &x);
Status QueueEmpty(Queue Q);
Status Palindrome(char *word)
/* 利用栈和队列判定字符序列word是否是回文 */
{
  char a,b,*p;
  Stack S;
  Queue Q;
  InitStack(S);
  InitQueue(Q);
  for(p=word;p&&*p!='@';p++)
  {
    Push(S,*p);EnQueue(Q,*p);
  }
  while(!StackEmpty(S))
  {
    Pop(S,a);
    DeQueue(Q,b);
    if(a!=b) return ERROR;
  }
  return OK;
}

⌨️ 快捷键说明

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