Note: how the application marks elements as "not available" is implementation specific.翻译
时间: 2024-04-24 18:22:35 浏览: 11
注意:应用程序如何标记元素为“不可用”是与实现相关的。这句话的意思是,标记元素为“不可用”的具体实现方式可能因应用程序而异,这取决于应用程序的具体实现和需求。例如,应用程序可以将某些元素的值设置为默认值或空值,以表示这些元素不可用。或者,应用程序可以使用特定的标志或标记来表示该元素不可用。因此,如何标记元素为“不可用”应该由应用程序自己决定,并在实现中进行具体规定。
相关问题
要求先运行完成pbynumbers: this.data.marks.length,再去运行this.goOn();
好的,我明白了。这是因为在运行 `this.goOn()` 之前,需要确保 `this.data.marks` 数组已经被正确地初始化并且 `length` 属性已经被计算。如果不先计算 `this.data.marks.length`,在后续代码中可能会出现错误。因此,需要先确保数组已经被正确地初始化之后才能调用 `this.goOn()` 方法。
Develop a NetBeans application that illustrates the applicability of one sorting algorithm on a collection of 10 items. The algorithm should sort the items in descending order. The algorithm is Bubble Sort algorithm. The collection of 10 items is defined and populated in the application code. You can decide the type and values of items stored in the collection. The algorithm must be implemented as part of a class called MyArrayList that extends the ArrayList class functionality with your sorting algorithm. [20 marks]
Here is an implementation of the requested NetBeans application:
```java
import java.util.ArrayList;
public class MyArrayList<T extends Comparable<T>> extends ArrayList<T> {
public void bubbleSortDescending() {
int n = this.size();
boolean swapped;
do {
swapped = false;
for (int i = 1; i < n; i++) {
if (this.get(i - 1).compareTo(this.get(i)) < 0) {
T temp = this.get(i - 1);
this.set(i - 1, this.get(i));
this.set(i, temp);
swapped = true;
}
}
n--;
} while (swapped);
}
public static void main(String[] args) {
MyArrayList<Integer> list = new MyArrayList<Integer>();
list.add(7);
list.add(2);
list.add(9);
list.add(4);
list.add(5);
list.add(1);
list.add(6);
list.add(8);
list.add(3);
list.add(10);
System.out.println("Original list: " + list);
list.bubbleSortDescending();
System.out.println("Sorted list: " + list);
}
}
```
In this implementation, we define a class called `MyArrayList` that extends the `ArrayList` class and adds our bubble sort algorithm to it. The `bubbleSortDescending` method sorts the list in descending order using the bubble sort algorithm. The `main` method creates a list of 10 integers and then calls the `bubbleSortDescending` method to sort the list in descending order. Finally, it prints out the original and sorted lists for verification.
Note that we use the `Comparable` interface to ensure that the items in the list can be compared with each other. This allows us to use the `compareTo` method to determine the order of the items in the list.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)