50分,高手请进来一下,关于程序调试的问题

cranley 2005-12-17 11:03:40
队列代码:
#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.”
请认真看一下,拜托了。
...全文
111 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
快乐鹦鹉 2005-12-20
  • 打赏
  • 举报
回复
请认真看一下,拜托了。
==不如你自己调试一下啊。眼睛毕竟不如编译器,调试更容易找到问题所在。
cranley 2005-12-20
  • 打赏
  • 举报
回复
我调试了很多遍阿,但是我就是看不出是什么问题啊〉我希望高手能帮我指点一下。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧