队列代码:
#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.”
请认真看一下,拜托了。
#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.”
请认真看一下,拜托了。
解决方案 »
- 有没有能已post方式访问的hyperlink控件
- >>>>>>>>>>>欢迎喜欢网络编程的加入[15045450]QQ群<<<<<<<<<<<<<
- 请教各位有关CRecordSet的问题
- 命令行参数问题
- 请教VC的union里不能有struct的问题
- 类向导生成类时有问题,系统问题?编译器问题?操作问题?病毒?
- [help]ATL DLL COM组件编译时,遇到两个静态库冲突的问题,请大家指点迷津
- 关闭对话框用什么方法比较好?
- GetCurrentDirectory(????)是怎么用的,有什么作用?
- 请大家看看这个东东该怎么做?
- 一如既往散分:纪念南京大屠杀68周年
- XP SP2下新建Socket的问题
==不如你自己调试一下啊。眼睛毕竟不如编译器,调试更容易找到问题所在。