huiwenshu.c

来自「数据结构里关于回文数判断的算法 另一种思路另一种解决办法~」· C语言 代码 · 共 93 行

C
93
字号
#include <stdio.h>
#define false -1
#define OK     1
#define   StackElementType  char
typedef struct node
{  StackElementType data;
   struct node  *next;

}LinkStackNode;
typedef LinkStackNode *LinkStack;
/*初始化堆栈*/
void InitStack(LinkStack *top)
       {   *top=(LinkStack)malloc(sizeof(LinkStackNode));
           (*top)->next=NULL;
        }
/*进栈函数*/
int Push(LinkStack top,StackElementType x)
{    LinkStackNode *temp;
     temp=(LinkStackNode *)malloc(sizeof(LinkStackNode));
     if(temp==NULL)
     return (false);
     temp->data=x;
     temp->next=top->next;
     top->next=temp;
     return (OK);
}
/*出栈函数*/
int Pop(LinkStack top,StackElementType *x)
{  LinkStackNode *temp;
   temp=top->next;
   if(temp==NULL)
     return (false);
     top->next=temp->next;
     *x=temp->data;
     free(temp);
     return (OK);
}
main()
{  LinkStack Q;
   StackElementType *C,c1,c2;
   C=NULL;
   InitStack(&Q);
   printf("please input some chars that include(&):\n");
   scanf("%c",&c1);
   while(c1!='%')
     {  if(c1=='&')
       break;
        Push(Q,c1);
/*       scanf("%c",&c1); */
       c1=getchar();
      }
      /*printf("please output huiwenshu:"); */
     /* while(Q->next!=NULL)
         { Pop(Q,C);
           printf("%c",*C);
           }           */
       getch();
      printf("please input hou ban bu fen chars:");
     /* scanf("%c",&c2);        */
    c2=getchar();
    Pop(Q,C);
      while(c2!='@')
         while((Q->next!=NULL)&&(c2==*C))
           {  Pop(Q,C);
           /*   scanf("%c",&c2);   */
              c2=getchar();
           }

      getch();
   }






















⌨️ 快捷键说明

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