全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:761
推到 Plurk!
推到 Facebook!

請問有人能解釋一下這個程式的流程嗎?

尚未結案
happybad
一般會員


發表:1
回覆:0
積分:0
註冊:2005-06-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-02 07:11:02 IP:220.136.xxx.xxx 未訂閱
#include #include struct node{ int data; struct node *lchild; struct node *rchild; }; struct node *root; void insert(struct node*,struct node*); void inorder(struct node*); void main(void){ int value; FILE *fp; fp=fopen("bst input.txt","r"); if(fp==NULL){ printf("開檔失敗"); } root = (struct node*)malloc(sizeof(struct node)); root=NULL; while(fscanf(fp,"%d",&value) != EOF){ struct node* temp = (struct node*)malloc(sizeof(struct node)); temp->lchild=NULL; temp->rchild=NULL; temp->data=value; if(root==NULL) root=temp; else insert(root,temp); } inorder(root); fclose(fp); } void inorder(struct node *root){ if(root!=NULL){ inorder(root->lchild); printf("%d\n",root->data); inorder(root->rchild); } } void insert(struct node *root,struct node *temp){ if(temp->data<=root->data) if(root->lchild==NULL) root->lchild=temp; else insert(root->lchild,temp); else if(root->rchild==NULL) root->rchild=temp; else insert(root->rchild,temp); } 請問有人能解釋一下這個程式的流程嗎? 小弟完全看不懂到底在作什麼? 感激不盡~~謝謝
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-02 09:08:28 IP:210.68.xxx.xxx 未訂閱
您好:    PO程式碼的方式請參考版規說明,煩請修改謝謝您的配合 >
暗黑破壞神
版主


發表:9
回覆:2301
積分:1627
註冊:2004-10-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-06-02 11:11:07 IP:210.66.xxx.xxx 未訂閱
你可以單步執行試看看囉。 看看它到底怎麼跑的囉。^_^
系統時間:2024-06-24 20:22:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!