夕阳_武士 2016-03-14 06:58 采纳率: 64.3%
浏览 1673

emacs进行gdb调试的相关问题

为什么打开gdb后无法调试?这是因为我的程序哪里有问题嘛?图片说明
以下是我的程序:
#include
#include
#include
#include
using namespace std;

struct BinaryTreeNode{
int m_nValue;
BinaryTreeNode* m_pLeft;
BinaryTreeNode* m_pRight;
};

BinaryTreeNode* CreateBinaryTreeNode(int value)
{
BinaryTreeNode* pNode = new BinaryTreeNode();
pNode->m_nValue = value;
pNode->m_pLeft = NULL;
pNode->m_pRight = NULL;

return pNode;

}

void ConnectTreeNodes(BinaryTreeNode* pParent, BinaryTreeNode* pLeft, BinaryTreeNode* pRight)
{
if(pParent != NULL)
{
pParent->m_pLeft = pLeft;
pParent->m_pRight = pRight;
}
}

void PrintTreeNode(BinaryTreeNode* pNode)
{
if(pNode != NULL)
{
printf("value of this node is: %d\n", pNode->m_nValue);

    if(pNode->m_pLeft != NULL)
        printf("value of its left child is: %d.\n", pNode->m_pLeft->m_nValue);
    else
        printf("left child is null.\n");

    if(pNode->m_pRight != NULL)
        printf("value of its right child is: %d.\n", pNode->m_pRight->m_nValue);
    else
        printf("right child is null.\n");
}
else
{
    printf("this node is null.\n");
}

printf("\n");

}

void PrintTree(BinaryTreeNode* pRoot)
{
PrintTreeNode(pRoot);

if(pRoot != NULL)
{
    if(pRoot->m_pLeft != NULL)
        PrintTree(pRoot->m_pLeft);

    if(pRoot->m_pRight != NULL)
        PrintTree(pRoot->m_pRight);
}

}

void DestroyTree(BinaryTreeNode* pRoot)
{
if(pRoot != NULL)
{
BinaryTreeNode* pLeft = pRoot->m_pLeft;
BinaryTreeNode* pRight = pRoot->m_pRight;

    delete pRoot;
    pRoot = NULL;

    DestroyTree(pLeft);
    DestroyTree(pRight);
}

}
void FindPathToLeaf(BinaryTreeNode* pNode,int expectedSum,
vector& ivec, int& currentSum);

void FindPath(BinaryTreeNode* pRoot, int expectedSum)
{
cout<<"Begin in here:";
if(pRoot==NULL)
return;
vector ivec;
int currentSum=0;
FindPathToLeaf(pRoot,expectedSum,ivec,currentSum);
}
void FindPathToLeaf(BinaryTreeNode* pNode,int expectedSum,
vector& ivec, int& currentSum)
{
currentSum+=pNode->m_nValue;
ivec.push_back(pNode->m_nValue);

bool isLeaf=pNode->m_pLeft==NULL&&pNode->m_pRight==NULL;
if(isLeaf&&expectedSum==currentSum)
    {
        cout<<"A path is:";
        for(vector<int>::iterator i=ivec.begin();i<ivec.end();i++)
            {
                cout<<(*i)<<" ";
            }
    }

if(pNode->m_pLeft!=NULL)
    FindPathToLeaf(pNode->m_pLeft, expectedSum, ivec, currentSum);
if(pNode->m_pRight!=NULL)
    FindPathToLeaf(pNode->m_pRight, expectedSum, ivec, currentSum);

currentSum-=pNode->m_nValue;
ivec.pop_back();

}

void Test(char* testName, BinaryTreeNode* pRoot, int expectedSum)
{
if(testName != NULL)
printf("%s begins:\n", testName);

FindPath(pRoot, expectedSum);

printf("\n");

}
// 10
// / \
// 5 12
// /\

// 4 7

// 有两条路径上的结点和为22
void Test1()
{
BinaryTreeNode* pNode10 = CreateBinaryTreeNode(10);
BinaryTreeNode* pNode5 = CreateBinaryTreeNode(5);
BinaryTreeNode* pNode12 = CreateBinaryTreeNode(12);
BinaryTreeNode* pNode4 = CreateBinaryTreeNode(4);
BinaryTreeNode* pNode7 = CreateBinaryTreeNode(7);

ConnectTreeNodes(pNode10, pNode5, pNode12);
ConnectTreeNodes(pNode5, pNode4, pNode7);

printf("Two paths should be found in Test1.\n");

char str[]="Test1";
Test(str, pNode10, 22);

DestroyTree(pNode10);

}

int main(int argc,char* argv[])
{
Test1();
return 0;
}

  • 写回答

2条回答

  • y1046086879 2016-03-20 09:59
    关注

    在main里设个断点

    b main
    r
    试试

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?