想看有关栈操作的基本例子请看本人另一篇博文:《栈的基本实现(入栈,出栈,清空,判断是否为空)》
本小程序可进行大数相加运算,仅限正整数。
经过简单的修改,解决逻辑导致的运算错误。但不保证我的代码百分之百没有错误。如在使用中发现存在运算错误。还请留言相告。谢谢
以下为代码。
#include <iostream>
#include <string>
using namespace std;
typedef class Node {
public:
int data;
class Node *pNext;
}NODE, *PNODE;
typedef class Stack {
public:
PNODE pTop;
PNODE pBottom;
}STACK, *PSTACK;
void init(PSTACK pS)
{
pS->pTop = new NODE;
pS->pBottom = pS->pTop;
pS->pTop->pNext = NULL;
}
void push(PSTACK pS, int val)
{
PNODE pNew = new NODE;
pNew->data = val;
pNew->pNext = pS->pTop;
pS->pTop = pNew;
}
void traverse(PSTACK pS)
{
PNODE p = pS->pTop;
while(p != pS->pBottom) {
cout << p->