Re: [問題] Selection Sorting的問題
看這樣子很像是你的Scope沒做好
你的selectArr確定是一個全區變數嗎?
※ 引述《sonicno111.bbs@ptt.cc (PP)》之銘言:
> 我貼一下現在的進度
> 只貼了執行SORTING那部份
> public void selectSort(){
> int tempArr[];
> int x=0;
> int s=0;
> tempArr= new int[selectArr.length];
> for (x=1;x<selectArr.length-1;x++){
> for (int i=1;i<selectArr.length-1;i++){
> if (tempArr[x-1]<selectArr[i-1]){
> tempArr[x-1]=selectArr[i-1];
> s=i-1;
> }
> }
> selectArr[s]=-1;
> }
> selectArr = tempArr;
> }
> 這樣子有沒有不對勁阿?@@
> (selectArr是之前就有設的陣列_
> 每次都說tempArr= new int[selectArr.length];這行出問題?
> java.lang.NullPointerException....這句不懂>/////<
> 另外...可不可以請教一下取亂數該用哪種rand的比較好呢?@@
> 謝謝
> 另外...還有有沒有其他可以不用讓selectArr[s]變成-1而讓他消失的方法?@@
> 每次都要再檢查那個-1好像是一種浪費...
> ※ 編輯: sonicno111 來自: 218.165.38.124 (05/14 13:37)
--
"To learn is what I need; "學習是我所須;
to teach those who needs 教導那些想要
to learn is my duty ..." 學習的是我的使命..."
--
◢◣ ︵︵ █▔◣ █▔█ █▔▔ █▔█ █▆▉ █ █▔█ █◣█ █▔●
◢◤█◣◢◣ ︵︵ █ █ █▁◤ █▁▁ █▁█ ▉▉▉ █ █▁█ █◥█ █ █
夢之大地 逼逼ㄟ四 █▁◤ █ █ █▁▁ █ █ ▉▉▉ █▁ █ █ █ █ █▁◤
※ Origin: <bbs.ccns.ncku.edu.tw> ◆ From: 140.116.116.76
討論串 (同標題文章)
完整討論串 (本文為第 3 之 15 篇):