50分,高手请进来一下,关于程序调试的问题
队列代码:
#include "StdAfx.h"
#include ".\myqueue.h"
//initialize
template <class T> myqueue<T>::myqueue(void)
{
count = current = maxqueue;
}
//Insert item
template <class T> void myqueue<T>::push(const T &item)
{
if(count > 0)
{
itm[count] = item;
count--;
}
else
printf("队列下溢!");
}
//Return the top item
template <class T> T myqueue<T>::top()
{
if(current <= count)
{
printf("队列下溢!");
return NULL;
}
else
return itm[current];
}
//Return the top item and Delete it
template <class T> T myqueue<T>::pop_top()
{
if(current > count)
return itm[current--];
else
{
printf("队列下溢!");
return NULL;
}
}
//Calculate the size of stack
template <class T> int myqueue<T>::size()
{
return (current - count);
}
//Delete stack
template <class T> myqueue<T>::~myqueue(void)
{
printf("abcd\n");
}
调用队列竖式打印二叉树
template <class Type> void BST<Type>::PrintTree(BSTnode<Type> *sub_root)
{
int blank_num, i, h, line;
i = 1;
h = 0;
line = 0;
blank_num = node_num(sub_root);
myqueue<BSTnode<Type> *> q1;
BSTnode<Type> *temp_node;
temp_node = sub_root;
while(1)
{
if((temp_node != NULL) && (i == pow(2,h)))
{
line = 0;
h++;
if(h > height(sub_root))
break;
line++;
printf("\n");
printBlank(int(blank_num*(2*line-1)/pow(2,h)));
cout<<temp_node->data;
if(h <= height(sub_root))
{
q1.push(temp_node->left);
q1.push(temp_node->right);
}
i++;
}
else if((temp_node != NULL) && (i != pow(2,h)))
{
line++;
printBlank(int(blank_num*2/pow(2,h)));
cout<<temp_node->data;
if(h <= height(sub_root))
{
q1.push(temp_node->left);
q1.push(temp_node->right);
}
i++;
}
else if((temp_node == NULL) && (i == pow(2,h)))
{
line = 0;
h++;
if(h > height(sub_root))
break;
line++;
printf("\n");
printBlank(int(blank_num*(2*line-1)/pow(2,h)));
printf(" ");
i++;
}
else
{
line++;
printBlank(int(blank_num*2/pow(2,h)));
printf(" ");
i++;
}
if(h > height(sub_root))
break;
temp_node = q1.pop_top();
}
printf("\nhere\n");
getchar();
getchar();
}
编译没问题,运行出现“Run-Time Check Failure #2 - Stack around the variable 'q1' was corrupted.”
请认真看一下,拜托了。