程序正确运行后出现如写错误:
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program received signal SIGSEGV, Segmentation fault.
源代码为:
#include <stdio.h>
#include <stdlib.h>
// translate BST to doublelist
typedef struct BSTTreeNode
{
int value;
struct BSTTreeNode *left;
struct BSTTreeNode *right;
}DoubleList;
//typedef BSTTreeNode DoubleList;
DoubleList * pHead;
DoubleList * pListIndex;
struct BSTTreeNode * BST_add_node(struct BSTTreeNode ** root, int value)
{
if (*root == NULL)
{
*root = (struct BSTTreeNode *) malloc(sizeof(struct BSTTreeNode));
(*root)->value = value;
(*root)->left = NULL;
(*root)->right = NULL;
return *root;
}
if ((*root)->value > value)
return BST_add_node( &(*root)->left, value);
else if((*root)->value < value)
return BST_add_node( &(*root)->right, value);
else
printf("the %d node has existed,not instert", value);
return NULL;
}
void convert_list (struct BSTTreeNode *root)
{
if (root == NULL) return ;
root->left = pListIndex;
if (pListIndex != NULL)
pListIndex->right = root;
else
pHead = root;
pListIndex = root;
printf("value is %d/n", root->value);
}
void BST_inorder(struct BSTTreeNode *root)
{
if (root == NULL)
return ;
if (root->left != NULL)
BST_inorder( root->left );
convert_list( root);
if (root->right != NULL)
BST_inorder( root->right );
}
int main(int argc, char *argv[])
{
struct BSTTreeNode **pRoot ;
*pRoot = NULL;
pHead = NULL;
pListIndex = NULL;
BST_add_node(pRoot, 10);
BST_add_node(pRoot, 3);
BST_add_node(pRoot, 6);
BST_add_node(pRoot, 18);
BST_add_node(pRoot,2);
BST_add_node(pRoot, 32);
BST_add_node(pRoot, 5);
BST_inorder(*pRoot);
return 0;
}