2. 简答题 参照教材中栈进栈和出栈的算法,编写一个程序实现如下功能:从键盘上接收用户输入的个位数,分别存入栈中,直到用户输入任意字母结束输入。然后逐个出栈,并计算栈中所有数值之和。

int Pop(LinkStack top,StackElementType x)
{
/
将栈top的栈顶元素弹出,放到x所指的存储空间中 */
LinkStackNode *temp;
temp=top->next;
if(temp==NULL) /栈为空/
return(FALSE);
top->next=temp->next;
x=temp->data;
free(temp); /
释放存储空间 /
return(TRUE);
}
int Push(LinkStack top,StackElementType x)
{
/
将数据元素x压入栈top中 */
LinkStackNode *temp;
temp=(LinkStackNode )malloc(sizeof(LinkStackNode));
if(temp==NULL)
return(FALSE); /
申请空间失败 /
temp->data=x;
temp->next=top->next;
top->next=temp; /
修改当前栈顶指针 */
return(TRUE);
}

链栈进栈 求和_风吹絮的博客-CSDN博客