none
C#氣泡排序法的錯誤 RRS feed

  • 問題

  •            //計算角度
                double X;
                double Y;
                double q;
                string[] soluation1 = new string[251];
                string[] soluation2 = new string[251];
                for (int z = 0; z < y.Length; z++)
                {
                    X = Customer[z].X;
                    Y = Customer[z].Y;
                    for (int k = 0; k < y.Length; k++)
                    {
                        Customer[z].asin = (double)Y / (Math.Pow((Math.Pow(X, 2) + Math.Pow(Y, 2)), 0.5));//math.sin(angle)
                        Customer[z].q = Math.Asin(Customer[z].asin) * 180 / Math.PI;
                        //angle=(Math.PI / 180) / Customer[z].asin;
                        if (X >= 0)
                        {
                            Customer[z].angle = 90 - Customer[z].q;
                        }
                        else
                        {
                            Customer[z].angle = 270 + Customer[z].q;
                        }
                       
                    }
                    //Console.WriteLine(Math.Asin(1)*180/Math.PI);
                    soluation1[z] += "顧客" + z + "的θ = " + Customer[z].asin;
                    soluation2[z] += "顧客" + z + "的角度 = " + Customer[z].angle;
                    //soluation1[z] +=  Customer[z].angle;
                    richTextBox4.Lines = soluation1;
                    richTextBox5.Lines = soluation2;
                    //角度做氣泡排序
                    string[] soluation3 = new string[251];
                    int space;
                    int forward = 1;
                    int t;
                    for (t = 1; t <=y.Length && forward == 1; t++)     // 外層迴圈控制比較回數
                    {
                        forward = 0;
                        double angle=Customer[z].angle;
                        for (int j = 1; j <= y.Length - t; j++)   

                        {
                            if (angle[j] < angle[j - 1])   

                            {
                                space = angle[j];
                                angle[j] = angle[j - 1];
                                angle[j - 1] = space;
                                forward = 1;
                            }
                        }
                    }
                    //soluation3 =angle;
                    richTextBox6.Lines = soluation3;
                }
            }

     

    粗體字的錯誤,錯誤訊息:無法套用有 [] 的索引至型別 'double' 的運算式

    2010年7月15日 上午 08:31

解答

所有回覆