#include"stdlib.h"#include"stdio.h"typedef char StackEntry;typedef struct node { //鏈棧的結點結構StackEntry item; //棧的資料元素類型struct node *next; //指向後繼結點的指標}NODE; typedef struct stack{NODE *top;}STACK; //初始化棧void InitStack(STACK *S){S->top=NULL;}//入棧void Push(STACK *S,StackEntry item){ NODE* p; p=(NODE*)malloc(sizeof(NODE)); if (!p) exit(0);else { p->item=item; p->next=S->top; S->top=p;}}//是否為空白棧int StackEmpty(STACK S){if (S.top==NULL) return true;else return false;}//出棧 void Pop(STACK*S, StackEntry *item){NODE *p;if (StackEmpty(*S)) exit(0);else { *item=S->top->item;p=S->top;S->top=p->next; free(p); }}void ReverseRead( ){ STACK S; //定義一個棧結構Schar ch;InitStack(&S); //初始化棧while ((ch=getchar())!='/n') //從鍵盤輸入字元,直到輸入分行符號為止Push(&S ,ch); //將輸入的每個字元入棧while (!StackEmpty(S)) { //依次退棧並輸出退出的字元Pop(&S,&ch);putchar(ch);}putchar('/n');}void main(){ReverseRead();}