<s>关于_p 栈_Ng 的_u 问题_n 。_w</s><s>为什么_r Push_v 函数_n top_nx 始终_d 是_v NULL_nx ？_w</s>
<s>引用_v 2_m 楼_n N_sev7_nx 的_u 回复_vn :_w #include_nx <_w stdio.h_nx >_w #include_nx <_w malloc.h_nx >_w #include_nx <_w string.h_nx >_w typedef_nx char_nx elemtype_nx ;_w typedef_nx struct_nx stacknode_nx {_w elemtype_nx data_nx ;_w struct_nx stacknode_nx *_w next_nx ;_w }_w StackNode_nx ;_w /_w /_w 建栈_v StackNode_nx *_w InitStack_nx (_w StackNode_nx *_w top_nx )_w {_w //_w 你_r 这_r 是_v 在_d 做_v 什么_r ？_w</s><s>？？_w</s><s>？_w 又_d 申请_v 空间_n ，_w 又_d 复制_v NULL_nx ，_w 你_r 到底_d 想_v 干_v 啥_r ？_w</s><s>top_nx =_w (_w StackNode_nx *_w )_w malloc_nx (_w sizeof_nx (_w StackNode_nx )_w )_w ;_w top_nx =_w NULL_nx ;_w return_nx top_nx ;_w }_w int_nx Judge_nx (_w StackNode_nx *_w top_nx )_w {_w if_nx (_w top_nx =_w =_w NULL_nx )_w {_w printf_nx (_w "_w 建栈_v 成功_a ._w \n_nx "_w )_w ;_w return_nx 1_m ;_w }_w else_nx {_w printf_nx (_w "_w 建栈_v 失败_v ！_w</s><s>\_w n_nx "_w )_w ;_w return_nx 0_m ;_w }_w }_w /_w /_w 进栈_v int_nx Push_nx (_w StackNode_nx *_w top_nx )_w {_w StackNode_nx *_w p_nx ,_w *_w q_nx ;_w char_nx *_w ch_nx =_w (_w char_nx *_w )_w malloc_nx (_w sizeof_nx (_w char_nx )_w *_w 20_m )_w ;_w /_w /_w /_w 只_d 改_v 了_u 一下_m 先_d 把_p 字符串_n 接收_v 完_v 了_y ，_w gets_nx (_w ch_nx )_w ;_w ////_w 然后_c 逐一_d 分析_v ，_w 具体_a 你_r 的_u 方法_n 该_v 怎么_r 改_v 还_d 没_v 时间_n 帮_v 你_r 看_v while_nx (_w '_w #_w '_w !_w =_w *_w ch_nx )_w {_w if_nx (_w *_w ch_nx =_w =_w '_w {_w '_w |_w |_w *_w ch_nx =_w =_w '_w (_w '_w |_w |_w *_w ch_nx =_w =_w '_w [_w '_w |_w |_w *_w ch_nx =_w =_w '_w <_w '_w )_w {_w p_nx =_w (_w StackNode_nx *_w )_w malloc_nx (_w sizeof_nx (_w StackNode_nx )_w )_w ;_w /_w /_w 如果_c 是_v 左边_f 的_u ，_w 进栈_v 。_w</s><s>p_nx -_w >_w next_nx =_w NULL_nx ;_w p_nx -_w >_w data_nx =_w *_w ch_nx ;_w p_nx -_w >_w next_nx =_w top_nx ;_w top_nx =_w p_nx ;_w }_w if_nx (_w *_w ch_nx =_w =_w '_w }_w '_w |_w |_w *_w ch_nx =_w =_w '_w )_w '_w |_w |_w *_w ch_nx =_w =_w '_w ]_w '_w |_w |_w *_w ch_nx =_w =_w '_w >_w '_w )_w {_w if_nx (_w top_nx =_w =_w NULL_nx )_w {_w printf_nx (_w "_w 栈空_n ._w \_w n_nx "_w )_w ;_w /_w /_w 如果_c 是_v 右边_f 的_u 且_c top_nx =_w NULL_nx 栈空_n ，_w 说明_v 不_d 平衡_a 。_w</s><s>还_d 有_v 符号_n 没有_d 平衡_an 。_w</s><s>return_nx 0_m ;_w }_w else_nx {_w switch_nx (_w *_w ch_nx )_w {_w case_nx '_w {_w '_w :_w if_nx (_w top_nx -_w >_w data_nx !_w =_w '_w }_w '_w )_w //_w 如果_c 是_v 右边_f 的且_u top_nx ！_w</s><s>=_w NULL_nx 出栈_v return_nx 0_m ;_w else_r break_nx ;_w case_nx '_w (_w '_w :_w if_r (_w top_nx -_w >_w data_nx !_w =_w '_w )_w '_w )_w return_v 0_m ;_w else_r break_a ;_w case_nx '_w [_w '_w :_w if_nx (_w top_nx -_w >_w data_nx !_w =_w '_w ]_w '_w )_w return_v 0_m ;_w else_r break_v ;_w case_nx '_w <_w '_w :_w if_r (_w top_nx -_w >_w data_nx !_w =_w '_w >_w '_w )_w return_v 0_m ;_w else_r break_nx ;_w }_w q_m =_w top_nx ;_w top_nx =_w top_nx -_w >_w next_nx ;_w free_nx (_w q_nx )_w ;_w }_w }_w +_w +_w ch_nx ;_w }_w if_r (_w top_nx =_w =_w NULL_nx )_w return_v 1_m ;_w else_r return_v 0_m ;_w }_w ;_w int_nx main_nx (_w )_w {_w StackNode_nx *_w top_nx =_w NULL_nx ;_w int_nx k_nx ;_w /_w /_w top_nx =_w InitStack_nx (_w top_nx )_w ;_w Judge_nx (_w top_nx )_w ;_w printf_nx (_w "_w 请_v 输入_v 带_v {_w }_w (_w )_w [_w ]_w <_w >_w 的_u 字符_n 的_u 字符_n 串_v 以_p “_w #_nx ”_w 号_n 键_n 结束_v :_w "_w )_w ;_w k_nx =_w Push_nx (_w top_nx )_w ;_w if_nx (_w k_nx =_w =_w 1_m )_w printf_nx (_w "_w 符号_n 平衡_a ._w \_w n_nx "_w )_w ;_w else_r printf_nx (_w "_w 符号_n 不_d 平衡_a ._w \_w n_nx "_w )_w ;_w return_nx 0_m ;_w }_w 我_r 去_v ，_w 居然_d 回到_v 你_r 那个_r 帖子_n 上_f 去_v 了_u 谢谢_v ！_w</s><s>我_r 的_u 方法_n 我_r 改_v 过来_v 了_y ，_w 不过_c 你_r 的_u 我_r 没_d 懂_v 啊_y 。_w</s><s>char_nx *_w ch_nx =_w (_w char_nx *_w )_w malloc_nx (_w sizeof_nx (_w char_nx )_w *_w 20_m )_w ;_w gets_nx (_w ch_nx )_w ;_w 是_v 什么_r 意思_n 啊_y ？_w</s><s>还_d 有_v 我_r 的_u 那_r 个_q StackNode_nx *_w InitStack_nx (_w StackNode_nx *_w top_nx )_w 是_v 不_d 是_v 也_d 没用_v ，_w 只_d 需要_v 将_p top_nx =_w NULL_nx ，_w 就_d 可以_v 了_y ？_w</s><s>是_v 吗_y ？_w</s>
