Link List 邏輯錯誤~?? |
答題得分者是:ikk
|
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
各位大大好:
目前我是想從VC已經寫好的 Link List 移植到BCB 但是在編譯的時候不會出錯 執行的時候才會出錯 想請各位大大幫我檢查看看哪裡錯了 我實在看不出來 麻煩各位了~!! 稍作說明一下: 目的是要做一個快速的分水嶺演算法 struct fwatershed 是我宣告來做 Link List 的一個結構 而buffg是用來存一張 W*H 圖像的一維指標陣列 所以在程式裡面已經有把值存進去了 當中的chaincodelb是要用來存放 鏈碼的值 但是只要到了while迴圈就會發生錯誤 [code cpp] struct fwatershed { int memory[2]; fwatershed *next; }; void __fastcall TForm1::fastwatershed1Click(TObject *Sender) { int *label = new int [w*h],ci,cj ; double *chaincodelb = new double[w*h],minneighbor,fwfleg ; fwatershed *current,*start,*first; fwatershed *temp; ; //step1 for(j=0;j for(i=0;i chaincodelb[i w*j]=4.0 ; //Current pixel minneighbor =255.0 ; fwfleg =4.0 ; for(cj=j-1;cj<=j 1;cj ) { for(ci=i-1;ci<=i 1;ci ) { if((cj>=0)&&(cj minneighbor=(abs(buffg[i w*j]-buffg[ci w*cj]) } } } chaincodelb[i w*j]=fwfleg; } } //step2 for(j=0;j for(i=0;i first=new fwatershed; current=first; start=current; for(cj=j-1;cj<=j 1;cj ) { for(ci=i-1;ci<=i 1;ci ) { if((cj>=0)&&(cj { (*start).memory[0]=i; (*start).memory[1]=j; cj=(j 1),ci=(i 1); } } } /* 從這裡 就會開始發生錯誤********************************************************************* while(start!=0) { for(cj=(*start).memory[1]-1;cj<=(*start).memory[1] 1;cj ) { for(ci=(*start).memory[0]-1;ci<=(*start).memory[0] 1;ci ) { if((cj>=0)&&(cj { chaincodelb[ci w*cj]=(8-(ci-i 1) 3*(cj-j 1)); current=(*current).next=new fwatershed; (*current).memory[0]=ci; (*current).memory[1]=cj; } } } start=(*start).next; } while(current!= 0) { temp=(*current).next; delete current; current=temp; } } } delete label,chaincodelb; } [/code]
------
恩... |
ikk
尊榮會員 發表:4 回覆:413 積分:768 註冊:2003-06-30 發送簡訊給我 |
|
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
您好:
看不太懂這個意思呢 current=(*current).next=new fwatershed; 這段不就是 new 一個 fwatershed 的 struct 那後面又把剛 new 出來的接地的這個動作 (*current).next = NULL; 可不可以請大大你稍作解釋一下呢? ===================引 用 ikk 文 章=================== current=(*current).next=new fwatershed; (*current).next = NULL;
------
恩...
編輯記錄
istillloving 重新編輯於 2009-04-20 10:20:47, 註解 無‧
|
ikk
尊榮會員 發表:4 回覆:413 積分:768 註冊:2003-06-30 發送簡訊給我 |
|
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
您好:
感謝你的解答 我還以為他會像檔案裡面有個EOF結尾呢 原來是要自己接地阿 但是照您的方法也是不行 我重看他的演算法再決定接哪好 謝謝喔 ===================引 用 ikk 文 章=================== current=(*current).next=new fwatershed; 是2段動作 (*current).next=new fwatershed; current=(*current).next; 所以這時候的current 裡的資料都是未知.. current->Next 可能不是NULL.
------
恩... |
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
您好:
我把它改成這樣 但是還是有一些問題想請教您 在第一個while裡面 [code cpp] //step2************************************************************************ for(j=0;j for(i=0;i first=new fwatershed; current=first; start=current; for(cj=j-1;cj<=j 1;cj ) { for(ci=i-1;ci<=i 1;ci ) { if((cj>=0)&&(cj { (*start).memory[0]=i; (*start).memory[1]=j; goto lb; } } } lb: (*start).next=NULL; //在這裡把 start 接地 while(start!=NULL) { for(cj=(*start).memory[1]-1;cj<=(*start).memory[1] 1;cj ) { for(ci=(*start).memory[0]-1;ci<=(*start).memory[0] 1;ci ) { if((cj>=0)&&(cj { chaincodelb[ci w*cj]=(8-(ci-i 1) 3*(cj-j 1)); current=(*current).next=new fwatershed; (*current).memory[0]=ci; (*current).memory[1]=cj; } } } start=(*start).next; //請問這裡的 //因為在最開始我把 start ,first,current 都指到同樣的地方 //是不是會跟隨著上述這段呢current=(*current).next=new fwatershed; //都有連結到一整段同樣的 link list 呢 } (*current).next=NULL; while(first != NULL) { temp=(*first).next; delete first; first=temp; } } } //step2************************************************************************ [/code]
------
恩...
編輯記錄
istillloving 重新編輯於 2009-04-20 11:25:52, 註解 無‧
istillloving 重新編輯於 2009-04-20 11:26:24, 註解 無‧ istillloving 重新編輯於 2009-04-20 11:27:12, 註解 無‧ istillloving 重新編輯於 2009-04-20 11:28:45, 註解 無‧ istillloving 重新編輯於 2009-04-20 11:29:23, 註解 無‧ istillloving 重新編輯於 2009-04-20 11:30:45, 註解 無‧ istillloving 重新編輯於 2009-04-20 11:31:20, 註解 無‧ |
ikk
尊榮會員 發表:4 回覆:413 積分:768 註冊:2003-06-30 發送簡訊給我 |
|
istillloving
高階會員 發表:33 回覆:182 積分:183 註冊:2008-10-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |