首页 \ 问答 \ Java:线程调用Runnable(Java : Thread calling Runnable)

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's run().

My Question is,

How the Thread class's run() method calls the Runnable interface's run() ?

thanks in advance.


原文:https://stackoverflow.com/questions/6632232
更新时间:2023-03-29 18:03

最满意答案

这是你的代码在这里我发现了一个错误。

而你的代码太复杂了,请再次浏览你的代码。

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++;
                    }
                }            

这里描述并显示了非常简单和时尚的方式。

en.wikipedia.org/wiki/Counting_sort#The_algorithm


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.

en.wikipedia.org/wiki/Counting_sort#The_algorithm

相关问答

更多
  • 谢谢@ 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 ...
  • 是的,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]) ...
  • 我已经提供了有关调试的提示,您可以在将来应用这些提示来查找这些问题。 问题1 int pivot=values[size]; 大小超出了排序范围的末尾。 在顶层,当范围是整个数组时,意味着它在数组之外。 而在其他级别,它要么在阵列之外,要么在枢轴值来自不同的范围。 发现此缺陷可能需要仔细检查代码或设计用于捕获此类错误的工具,例如内置于某些编译器中的错误。 更困难的方法是使用print语句或调试器检查运行时行为,并识别第一个pivot不是数组中的值。 使用已知输入而不是随机输入进行测试有助于使用此方法,因为 ...
  • 这是你的代码在这里我发现了一个错误。 而你的代码太复杂了,请再次浏览你的代码。 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#数组索引是从零开始的,而您的伪代码是从一开始的。 话虽这么说,这是错误: 1)主要方法 MergeSort(ref unsortedArray, 1, unsortedArray.Length); 必须改为: MergeSort(ref unsortedArray, 0, unsortedArray.Length - 1); 2)合并方法 leftArray[i] = unsortedArray[leftIndex + i - 1]; 必须改为: leftArray[i ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。