错误:越界Java气泡排序 public void sort()//从堆栈中提取数字,然后对其进行排序,然后按顺序将其放回堆栈中。 //不管它在哪里停止。注:为新封头制作温度变量将导致封头损坏。 //一旦老头撞到a-1;或小于其自身的值,它将从“排序头”开始 // ???????????????????????????????????????????????????????????????????????????????????????????????? { int[]numbers=newint[node-1];//其他一切都应该正常工作。 for(int i=size;i>1;i--)//for循环,用于需要排序的元素的numberof/size。3 { int temphead=头部; numbers[i]=(stack.getpeople(temphead));//为堆栈提取一个值 temphead=stack.getBLink(temphead);//将该值拉回到链接,并将其添加到新的lead中。 } int-tempVar; for(int i=0;i1;i--) { getpeople(temphead=numbers[i]);//将排序后的列表添加回堆栈 temphead=stack.getBLink(temphead);//重置临时头。 } }
//上述错误被标记为越界。这可能是我遗漏的一些非常简单的东西,我不相信它本身就是冒泡排序函数,因为逻辑是正确的?然而,这可能是一个出站错误,因为我的堆栈中没有编程冷凝,如果是这种情况,我将不得不用堆栈和其他一些方法更新这篇文章-----感谢您的帮助,当您拨打[j+1]号码时,您将超出阵列的界限。在您认为-错误:越界Java气泡排序 public void sort()//从堆栈中提取数字,然后对其进行排序,然后按顺序将其放回堆栈中。 //不管它在哪里停止。注:为新封头制作温度变量将导致封头损坏。 //一旦老头撞到a-1;或小于其自身的值,它将从“排序头”开始 // ???????????????????????????????????????????????????????????????????????????????????????????????? { int[]numbers=newint[node-1];//其他一切都应该正常工作。 for(int i=size;i>1;i--)//for循环,用于需要排序的元素的numberof/size。3 { int temphead=头部; numbers[i]=(stack.getpeople(temphead));//为堆栈提取一个值 temphead=stack.getBLink(temphead);//将该值拉回到链接,并将其添加到新的lead中。 } int-tempVar; for(int i=0;i1;i--) { getpeople(temphead=numbers[i]);//将排序后的列表添加回堆栈 temphead=stack.getBLink(temphead);//重置临时头。 } },java,sorting,indexoutofboundsexception,Java,Sorting,Indexoutofboundsexception,//上述错误被标记为越界。这可能是我遗漏的一些非常简单的东西,我不相信它本身就是冒泡排序函数,因为逻辑是正确的?然而,这可能是一个出站错误,因为我的堆栈中没有编程冷凝,如果是这种情况,我将不得不用堆栈和其他一些方法更新这篇文章-----感谢您的帮助,当您拨打[j+1]号码时,您将超出阵列的界限。在您认为- public void sort() // pulls the numbers off the stack then orders them, putting back onto stack
public void sort() // pulls the numbers off the stack then orders them, putting back onto stack in order.
// Does not care where the it left off. Note: making a temp varible for the new head will head.
// once the old head hits a -1; or a value less than it self it will start from the "sort head"
// ????????????????????????????????????????????????????????????????????????????????????????????????
{
int[] numbers = new int[node - 1]; //everything else should be working fine.
for(int i = size ; i > 1; i--) //for loop for the numberof/size of the elements needed to be sorted.3
{
int temphead = head;
numbers[i] = (stack.getpeople(temphead)); // pulls a value for a stack
temphead = stack.getBLink(temphead); // pulls that values back link and adds it to the new lead.
}
int tempVar;
for (int i = 0; i < numbers.length; i++) //used for bubble sort.
{
for(int j = 0; j < numbers.length - 1; j++) // used for bubble sort.
{
if(numbers[i] > numbers[j + 1]) //ERROR HERE Out of bounds
{
tempVar = numbers [j + 1]; //ERROR HERE Out of bounds
numbers [j + 1] = numbers [i]; //ERROR HERE Out of bounds
numbers [i] = tempVar; //ERROR HERE Out of bounds
}
}
}
int temphead = head;
for(int i = size ; i > 1; i--)
{
stack.getpeople(temphead = numbers[i]); //adds the sorted list back to the stack
temphead = stack.getBLink(temphead); //resets the temp head.
}
}
for(int j=0;j
+1因为计算机科学中的两个主要问题是缓存失效、命名错误和一对一错误。假设是这样,请给出我的答案。否则,请发布您所做的修复工作,并接受这一点。
for(int j = 0; j < numbers.length - 1; j++) { // <--- The error was here.
// used for bubble sort.
if(numbers[i] > numbers[j + 1]) // When j = (number.length - 1) [0 based indexing],
// then j + 1 = (number.length) and that is
// out of bounds.