开发平台(Platform): (Ex: Win10, Linux, ...)
MacOS
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
GCC
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
问题(Question):
在macOS一直出现segmentation fault(数字越来越大)
在win10结果错误1232367
在Linux正确无误1245367
喂入的资料(Input):
预期的正确结果(Expected Output):
124532
错误结果(Wrong Output):
[1] 2658 segmentation fault
>./a.out
[1] 2710 segmentation fault
>./a.out
程式码(Code):(请善用置底文网页, 记得排版)
#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node *_child;
struct Node *_child2;
};
struct Node *creatTree(){
struct Node *_node = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node2 = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node3 = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node4 = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node5 = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node6 = (struct Node*)malloc(sizeof(struct Node));
struct Node *_node7 = (struct Node*)malloc(sizeof(struct Node));
_node -> data =1;
_node2 -> data =2;
_node3 -> data =3;
_node4 -> data =4;
_node5 -> data =5;
_node6 -> data =6;
_node7 -> data =7;
_node -> _child =_node2;
_node -> _child2=_node3;
_node2 -> _child =_node4;
_node2 -> _child2=_node5;
_node3 -> _child =_node6;
_node3 -> _child =_node6;
_node3 -> _child2=_node7;
return _node;
}
void printAll_DFS(struct Node* node){
if(node!=NULL){
printf("%d",node->data);
if(node->_child!=NULL){
printAll_DFS(node -> _child);
}
if(node->_child2!=NULL){
printAll_DFS(node -> _child2);
}
}
}
int main(){
struct Node * tmp = NULL;
tmp = creatTree();
printAll_DFS(tmp);
printf("\n");
}