user-0 提问: 使用链表建立一个后入先出的栈，将输入的一串字符反序输出。 

回复:
user: user-1
content: 创建链表，头插法即可。仅供参考： #include <list> #include <iostream> using namespace std;  int main(void) { 	char c; 	list<char> lst;  	while (cin >> c) 	{ 		if (c == '#') break; 		lst.push_front(c); 	}  	for (char c : lst) cout << c;  	return 0; }

user: user-2
content: 可以先实现一个链表，链表的创建采用头插法，可以创建一个带有哨兵的链表；每次新的节点都插在哨兵节点的后面。这样遍历从哨兵后的第一个节点开始，这样可以实现后入先出。

user: user-3
content: 链式栈，供参考  #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #define Empty 0  //栈空 #define Avail 1  //栈可用  typedef char ElemType;  typedef struct SNode {     ElemType data;     struct SNode *next; }StackNode;  typedef struct LStack {     StackNode *top;  //栈顶指针     StackNode *bot;  //栈底指针     int length;      //栈长度   }LinkStack;  LinkStack InitStack(LinkStack pStack); LinkStack Push(LinkStack pStack, ElemType c); void Pop(LinkStack pStack); int StackEmpty(LinkStack pStack); LinkStack ClearStack(LinkStack pStack); void DisplayStack(LinkStack pStack);  int main(void) {     LinkStack p;     char ch;     p.length = 0;     p = InitStack(p);      printf("输入字符，以#结束\n");     scanf("%c", &ch);      while (ch != '#')     {         p = Push(p, ch);                 scanf("%c", &ch);     }      DisplayStack(p);      ClearStack(p);     system("pause");     return 0; }  //入栈 LinkStack Push(LinkStack pStack, ElemType c) {         StackNode *temp;     temp = (StackNode*)malloc(sizeof(StackNode));     if (temp == NULL)     {         printf("内存分配失败！\n");         return pStack;     }      if (StackEmpty(pStack) == Empty)      //如果栈为空     {         pStack.top = pStack.bot = temp;   //栈顶、栈底指针都指向新建结点         temp->next = NULL;                 pStack.top->data = c;         pStack.length++;         return pStack;     }     else                                  //栈不为空     {         temp->next = pStack.top;          //新建结点指向原来的栈顶          pStack.top = temp;                //栈顶指针指向新建结点                pStack.top->data = c;         pStack.length++;         return pStack;     } }  //出栈 void Pop(LinkStack pStack) {     StackNode *Second;     if (StackEmpty(pStack) == Empty)     {         printf("栈为空！\n");         return pStack;     }      if (pStack.top == pStack.bot)        //如果是最后一个元素     {         printf("%c\n", pStack.top->data);         free(pStack.top);         pStack.top = pStack.bot = NULL;   //栈顶、栈底指针都置为空         pStack.length--;             }      printf("%c", pStack.top->data);     Second = pStack.top->next;     free(pStack.top);     pStack.top = Second;     pStack.length--;     }  //判断栈是否为空 int StackEmpty(LinkStack pStack) {     if (pStack.top == NULL && pStack.bot == NULL)     {         return Empty;     }     else         return Avail; }  //遍历栈 void DisplayStack(LinkStack pStack) {     if (StackEmpty(pStack) == Empty)     {         printf("栈为空！\n");         return;     }      while (pStack.top != NULL)     {         printf("%c", pStack.top->data);         pStack.top = pStack.top->next;     }     printf("\n"); }  //清空栈 LinkStack ClearStack(LinkStack pStack) {     StackNode *del;     while (pStack.top != NULL)     {         del = pStack.top->next;         free(pStack.top);         pStack.top = del;     }     return pStack; }  //初始化 LinkStack InitStack(LinkStack pStack) {     pStack.top = pStack.bot = NULL;     pStack.length = 0;      return pStack; }