開發平台(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");
}