夕阳_武士 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
    试试

    评论

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项