我在这个考试复习题上是空白的,任何人都可以帮助我入门吗?在findMinPos中,我对这三个参数感到困惑,我如何访问数据数组中的节点?即使它是递归方法,我可以使用循环吗?使用递归将最小数组的伪代码转换为Java代码
public class ArraySwapMin
{
public static void swapMin(int[] data, int cur)
{
int min = findMinPos(data, cur, cur);
/////////////////////////////////////////////////////////////
// swap the min position value with the one in the cur position
////////////////////////////////////////////////////////////////
}
/**
* Check the nodes in "data" from position "start" to the end of the array.
* to see if any value in this part of the array is less than the min
* value found so far (up to the "cur" position).
*/
private static int findMinPos(int[] data, int cur, int minPosSoFar)
{
//////////////////////////////////////////////////////////////
// Compare this entry's value (if it is a valid entry) with the
// value in the entry "minPosSoFar". If this value is less, then
// this entry is now the "minPosSoFar".
// Recurse for the rest of the array.
///////////////////////////////////////////////////////////////
return minPosSoFar;
}
/**
* unit tester
*/
public static void main(String[] args)
{
int[] data = { 12, 3, 10, 5, 1, 8 };
int count = 0;
System.out.println("++++++++++++++++ ArraySwapMin ++++++++++++++++");
printArray("starting array ", data);
for (int i = 0; i < data.length - 1; i++)
{
swapMin(data, i);
printArray("swap Min with " + i, data);
}
}
public static void printArray(String label, int[] data)
{
System.out.print(label + ": [ ");
for (int i = 0; i < data.length - 1; i++)
System.out.print(data[ i ] + ", ");
System.out.println(data[ data.length - 1 ] + " ]");
}
}
1 )你已经描述了一个问题,但至今没有提出问题(更不用说具体的可回答的问题)。你的问题是什么? 2)请参阅[开始编写程序](http://home.earthlink.net/~patricia_shanahan/beginner.html)以获取重要提示。 – 2013-05-08 13:25:24
对不起,我现在编辑 – codeAligned 2013-05-08 13:32:27