Dean526199572 2015-04-26 08:49
浏览 676

我写的建立表达式二叉树的一个函数,delete[]p和B.pop(a1)出错,不明白为什么

BinaryTree::BinaryTree(string A){
arrStack B(NUM);
BinaryTreeNode a1(" "), a2(" ");
int i = 0;
while (A[i] != '='){
char *p = new char[];
char *q = p;
int j = 0;
if ((int)A[i] >= 48 && (int)A[i] <= 57){
while ((int)A[i] >= 48 && (int)A[i] <= 57){
*p = A[i];
i++;
j++;
p++;
}
BinaryTreeNode node1(p);
B.push(node1);
}
else if ((int)A[i] == 32){
i++;
}
else if ((int)A[i] == 42 || (int)A[i] == 43 || (int)A[i] == 45 || (int)A[i] == 47){
*p = A[i];
BinaryTreeNode node2(p);
B.pop(a1);
B.pop(a2);
node2.setLeftChild(&a2);
node2.setRightChild(&a1);
B.push(node2);
i++;
}
p = q;
delete []p;
}
B.pop(a1);
*root = a1;
}

这个arrStack栈是我自己写的,代码如下:
template
class arrStack{
private:
int mSize;
int top;
T *st;
public:
arrStack(int size){
mSize = size;
top = -1;
st = new T[mSize];
}
arrStack(){
top = -1;
}
bool push(T item){
if (top == mSize - 1){
cout << "The arrStack has full!" << endl;
return false;
}
st[++top] = item;
return true;
}
bool pop(T &item){
if (top == -1){
cout << "The arrStack is empty!" << endl;
return false;
}
item = st[top--];
return true;
}
T topItem(){
if (top == -1){
cout << "The arrStack is empty!" << endl;
return false;
}
return st[top];
}
bool isEmpty(){
if (top == -1)
return true;
else
return false;
}
bool isFull(){
if (top == mSize - 1)
return true;
else
return false;
}
};

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗