- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
import java.util.Random;
public class TestBed {
public static void main(String a[]) {
// creating the array
int[] array = new int[100];
Random random = new Random();
// changing the variable of my clone array for reference
int[] arr = cloneArray(array);
for (int i1 = 0; i1 < 100; i1++)
array[i1] = random.nextInt(100) + 1;
// print out of bubble sort before and after the sort
System.out
.println("***********************Bubble Sort ****************************");
arr = cloneArray(array);
System.out.println("Values Before the sort:\n");
printArray(arr);
System.out.println();
bubble_srt(arr);
System.out.print("Values after the sort:\n");
printArray(arr);
// print out of selection sort before and after the sort
System.out.println();
System.out
.println("********************Selection Sort*****************************");
System.out.println(" Selection Sort\n\n");
arr = cloneArray(array);
System.out.println("Values Before the sort:\n");
printArray(arr);
System.out.println();
selection_srt(arr);
System.out.print("Values after the sort:\n");
printArray(arr);
System.out.println();
Stack stack = new Stack();
}
public static int[] buildArray(int bound) {
return null;
}
// clone array as a data type
public static int[] cloneArray(int[] data) {
return (int[]) data.clone();
}
// print array as a data type
public static void printArray(int[] data) {
// while there are still numbers left in the array print out the next
// value
for (int i = 0; i < data.length; i++)
System.out.print(data[i] + " ");
}
// bubble syntax
public static void bubble_srt(int a[]) {
int t = 0;
for (int i = 0; i < a.length; i++) {
for (int j = 1; j < (a.length - i); j++) {
if (a[j - 1] > a[j]) {
t = a[j - 1];
a[j - 1] = a[j];
a[j] = t;
}
}
}
}
// selection syntax
public static void selection_srt(int array[]) {
for (int x = 0; x < array.length; x++) {
int index_of_min = x;
for (int y = x; y < array.length; y++) {
if (array[index_of_min] > array[y]) {
index_of_min = y;
}
}
int temp = array[x];
array[x] = array[index_of_min];
array[index_of_min] = temp;
}
}
}
从这里我必须链接我的堆栈类,但我不知道如何正确地将这两个类放在一起,我是编程新手,我的学校把我扔进了一个对我来说太高的java类,现在我陷入了5几周后。
public class Stack {
Node top;
int size;
public Stack() {
top = null;
size = 0;
}
public int pop() {
if (top != null) {
int item = top.data;
top = top.next;
size--;
return item;
}
return -1;
}
public void push(int data) {
Node t = new Node(data);
t.next = this.top;
this.top = t;
size++;
}
public boolean isEmpty() {
return size <= 0;
}
public int getSize() {
return size;
}
public int peek() {
return top.data;
}
public void printStack() {
Node n = this.top;
int pos = this.getSize();
while (pos > 0) {
System.out.println("Position: " + pos + " Element: " + n.data);
if (pos > 0) {
n = n.next;
}
pos--;
}
}
}
class Node {
public int data;
public Node next;
Node(int d) {
data = d;
next = null;
}
public int getData() {
return data;`enter code here`
}`enter code here`
{
Stack s = new Stack();
s.push(9);
s.push(2);
s.push(7);
s.push(3);
s.push(6);
s.push(4);
s.push(5);
System.out.println("Size is: " + s.getSize());
// s.printStack();
int size = s.getSize();
for (int i = 0; i < size; i++) {
System.out.print(s.pop() + " ");
}
}
}
最佳答案
在Stack类文件的开头,创建一个包名,例如:
package com.example.testcode;
然后在您的 TestBed 类文件中,从包中导入您的 Stack 类,例如:
import com.example.testcode.Stack;
关于java - 我需要帮助将我的堆栈类链接到我的 TestBed 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22801222/
我有一个组件,它有两个依赖项:一个是 LOCALE_ID在 Angular 中全局定义,另一种是语言,在组件中定义为 { provide: LANGUAGE_TOKEN, useValue: navi
我正在尝试测试一个具有依赖性的简单组件。我试图模拟这种依赖关系,但真正的服务仍在构建中。有人能看出我错过了什么吗? 这是我的组件: import { Component } from "@angula
import java.util.Random; public class TestBed { public static void main(String a[]) { // creatin
我目前正在尝试为在其 html 中使用另一个组件标记的组件编写一组单元测试。 但是我似乎无法编译这个其他组件。我尝试了几种使用 NO_ERROR_SCHEMA 的方
我有 MainComponent,它使用 ChildComponentA 作为 @ViewChild。 MainComponent 正在调用 ChildComponentA 上的方法。 我想编写一个模
当对测试夹具使用以下配置时,我收到无法找到标签的投诉。直接在 AppModule 中替换 MockSelectionToolComponent 工作正常,所以一定是别的东西...... // Add
在基于 Angular 8.1.2 和 Ionic 4 的应用程序项目中,我为 typescript 中的一个简单类编写了单元测试。这与“npm test”配合得很好。为了准备需要模拟的更复杂的类,我
可以说我有一个如下所示的测试配置 TestBed.configureTestingModule({ imports: [HttpClientTestingModule],
我正在尝试测试在 App Engine 上运行的应用程序。我正在使用 the Testbed framework ,到目前为止,除了以下意外行为外,它就像一个魅力: 像这样的测试将工作得很好(没有框架
如何使用另一个提供者的实例在 TestBed.configureTestingModule() 中实例化一个提供者? 一个例子(显然不起作用): beforeEach(() => { TestBe
我正在使用 TestBed 进行 Angular 2+ 单元测试。场景,我想验证我的组件,即伪元素的颜色。 组件.ts label::before { right: 0;
我想了解这个 testb 指令 (x86-64) 会做什么。 testb $1, %al 这里 $1 的值(value)是多少。是全部 (0xFF) 还是单个 1 (0x1)? 程序集由 clang
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
我正在编写 TestBed 单元测试。 有一个特定的组件,它是被测组件的子组件。该子组件在测试运行时会导致错误。该子组件与测试本身无关;这只会引起问题。 我想用一个虚拟的替换它,或者阻止它被添加。 有
我是 Angular 2 的 Jasmine 新手,在编写测试用例时我经常使用 TestBed 对象并收到错误:请在测试前调用“TestBed.compileComponents”。 如何解决这个错误
我们正在使用 TestBed.overrideComponent(CoolComponent, { set: { template: 'i am the fake componen
我使用 Angular TestBed 进行了一些单元测试。即使测试非常简单,它们运行起来也非常慢(平均每秒 1 个测试 Assets )。 即使在重新阅读 Angular 文档后,我也找不到性能如此
我有一个组件,它接收组件的组件类以动态创建为子组件。 let componentFactory = this.componentFactoryResolver.resolveComponentFact
我正在使用带有 Jest 的 Angular 7 并且正在模拟组件的提供者。很多时候我需要更改在 TestBed 之后注入(inject)到组件中的内容。已编译,并且使用此代码执行此操作没有任何问题:
我实际上正在尝试构建一个 flutter 应用程序窗口,但我收到了这条错误消息: flutter build windows CMake Error:
我是一名优秀的程序员,十分优秀!