感谢“ sunnyan” 的讲解,下面是我写的代码,估计问题不少,还请大家给指点一下。。
第二题:我理解应该是这个时钟对应一个任务列表,没有新的加入。我的思路是写一个定时器,根据时间查找对应的任务去执行
第三题:
public class T110 {
public static void main(String args[]) {
int[] k = { 1, 2, 3, 4, 5 };
getOutput(k);
}
public static void getOutput(int[] k) {
Queue queue = new LinkedList(); // ListedList implements Queue
for (int i = 0; i0) {
Object o = queue.poll(); // 出队
System.out.print(o);
System.out.print(" ");
}
}
}
第四题:冒泡和选择
import java.sql.Array;
import java.util.Arrays;
/**
* 用Java语言实现的各种排序,使用插入排序、冒泡排序、选择排序、Shell排序、快速排序、归并排序、堆排序任意一种 对数组或列表中元素
* 1,0,3,8,5,6,7,9,12,14,56,24,35,79,90,87,56,4进行排序, 排序完成后使用二分查找法找出79的位置
*
* 先排序再进行二分查找
*
* @author Administrator
*
*/
public class SortAndFind {
// sort the array by Bubble arithmetic
public static int[] getSortByBubble(int[] arr) {
int out = 0, in = 0;
for (out = arr.length - 1; out > 1; out--) {
for (in = 0; inarr[in + 1]) {
int temp = arr[in];
arr[in] = arr[in + 1];
arr[in + 1] = temp;
}
}
}
for (int i = 0; iend) {
index = -1;
}
if (target > midVal) {
index = binarySearch(arr, target, middle + 1, end);
} else if (target < midVal) {
index = binarySearch(arr, target, begin, middle - 1);
} else {
index = middle;
}
// System.out.println(index);
return index;
}
public static void main(String args[]) {
int[] tmpArr = { 1, 0, 3, 8, 5, 6, 7, 9, 12, 14, 65, 24, 35, 79, 90,
87, 56, 4 };
int index = 0;
// getSortArray(tmpArr);
//
index = binarySearch(getSortByBubble(tmpArr), 8, 0, tmpArr.length - 1);
Arrays.sort(tmpArr);
index = binarySearch(tmpArr, 8, 0, tmpArr.length - 1);
// binarySearch1(getSortArray(tmpArr), 79);
System.out.println();
System.out.println(index);
}
}
|