Java:线程调用Runnable(Java : Thread calling Runnable)
我是java的新手。 一个疑问。
我在内部读到,Thread类的
run()
方法调用Runnable接口的run()
。我的问题是,
Thread类的
run()
方法如何调用Runnable接口的run()
?提前致谢。
I am newbie to java. One doubt.
I read that, internally, Thread class's
run()
method calls the Runnable interface'srun()
.My Question is,
How the Thread class's
run()
method calls the Runnable interface'srun()
?thanks in advance.
原文:https://stackoverflow.com/questions/6632232
最满意答案
这是你的代码在这里我发现了一个错误。
而你的代码太复杂了,请再次浏览你的代码。
for (i = n - 1; i >= 0; i--) { anothersmallestvalue = x; for (j = 0; j <= lengthof_B ; j++) { if (a[i] == anothersmallestvalue) { temp = b[j]; c[temp - 1] = anothersmallestvalue; b[j] = b[j] -1 ;// Possible Mistake I think here } anothersmallestvalue++; } }
这里描述并显示了非常简单和时尚的方式。
This Is Your Code Here I found a mistake.
And your Code is too complex Please Go through your code Once more.
for (i = n - 1; i >= 0; i--) { anothersmallestvalue = x; for (j = 0; j <= lengthof_B ; j++) { if (a[i] == anothersmallestvalue) { temp = b[j]; c[temp - 1] = anothersmallestvalue; b[j] = b[j] -1 ;// Possible Mistake I think here } anothersmallestvalue++; } }
the very simple and stylish way is described and shown here.
相关问答
更多-
谢谢@ mephi42。 这是更新版本。 问题出在你的bubbleSort函数中。 您应该使用偏移量乘以元素大小来添加address 。 正确的代码应该是: void bubbleSort(void *address, int len, size_t ele_size, int (*comp)(void *a, void *b), void (*swap)(void *a, void *b)) // bubble sort function allow to user to write it's compa ...
-
在您的示例中,您已经在扫描输入数组以查找最大值。 缺少的是您还没有扫描输入数组以找到最小值。 如果添加它,然后知道最小值,则可以偏移数组索引的范围以允许负数(如果只处理正数,甚至可能减小数组的大小)。 这看起来像这样: static void Sort(int[] array) { int min = int.MaxValue, max = int.MinValue; for (int i = 0; i < array.Length; i++) { if (arra ...
-
在C#中实现List
?(Implementation of List [2022-01-28]in C#?) 是的,List <>是一个数组。 是的,Insert()是一个O(n)操作。 重要的是它以这种方式工作,现代处理器非常依赖于它们的缓存。 机器中的RAM 非常慢,比处理器慢得多。 缓存可以快速顺序访问内存。 这与LinkedList <>的作用相反。 单个缓存未命中需要花费数百个cpu周期。 请注意LinkedList <>的另一个显着缺点,索引成本为O(n),除非您可以按顺序索引。 列表总是O(1)。 这些只是粗略的指导原则,没有人可以建议你用LinkedList替换你的List。 只有剖析器才能做到这一 ... -
string str = "contamination"; IEnumerable
sortedSubstrings = Enumerable.Range(0, str.Length) .Select(i => str.Substring(i)) .OrderBy(s => s); string str = "contamination"; IEnumerable sortedSubstrings = ... -
您的版本的问题是,如果元素具有卫星数据,它将无法工作。 CLRS版本可行,而且稳定。 编辑: 这是Python中CLRS版本的实现,它按键对键(键,值)进行排序: def sort(a): B = 101 count = [0] * B for (k, v) in a: count[k] += 1 for i in range(1, B): count[i] += count[i-1] b = [None] * len(a) for i in range(len(a) ...
-
错误包含在函数Heapify 。 功能的更正版本: private void Heapify(int[] arr, int index) { int left = 2 * index + 1; int right = 2 * index + 2; int largest = index; if (left <= heapSize && arr[left] > arr[index]) ...
-
C中的快速排序实现(Quick sort implementation in C)[2023-02-04]
我已经提供了有关调试的提示,您可以在将来应用这些提示来查找这些问题。 问题1 int pivot=values[size]; 大小超出了排序范围的末尾。 在顶层,当范围是整个数组时,意味着它在数组之外。 而在其他级别,它要么在阵列之外,要么在枢轴值来自不同的范围。 发现此缺陷可能需要仔细检查代码或设计用于捕获此类错误的工具,例如内置于某些编译器中的错误。 更困难的方法是使用print语句或调试器检查运行时行为,并识别第一个pivot不是数组中的值。 使用已知输入而不是随机输入进行测试有助于使用此方法,因为 ... -
在C#中计数排序实现(Counting Sort Implementation in C#)[2022-06-19]
这是你的代码在这里我发现了一个错误。 而你的代码太复杂了,请再次浏览你的代码。 for (i = n - 1; i >= 0; i--) { anothersmallestvalue = x; for (j = 0; j <= lengthof_B ; j++) { if (a[i] == a ... -
适合我的工作: class Program { static void Main() { string[] names = { "John Doe", "Doe John", "Another Name", "Name Another" }; InsertSort(names); foreach (var item in names) { Console.WriteLine(item); ...
-
C#中的MergeSort实现(MergeSort Implementation in C#)[2022-05-05]
正如在注释中正确指出的那样,C#数组索引是从零开始的,而您的伪代码是从一开始的。 话虽这么说,这是错误: 1)主要方法 MergeSort(ref unsortedArray, 1, unsortedArray.Length); 必须改为: MergeSort(ref unsortedArray, 0, unsortedArray.Length - 1); 2)合并方法 leftArray[i] = unsortedArray[leftIndex + i - 1]; 必须改为: leftArray[i ...