简体   繁体   English

快速排序中的gwt延迟计时器

[英]delay timer in gwt on quick sort

I'm writing a quick sort algorithm in GWT, between each iteration I'm trying to print the current status. 我正在GWT中编写一种快速排序算法,在每次迭代之间我都尝试打印当前状态。

This is the method 这是方法

private int partition(int[] list_of_numbers, int first, int last) {

        int pivot = list_of_numbers[first];
        int up = first;
        int down = last;

        do {
            while ((up < last) && pivot >= list_of_numbers[up]) {
                up++;
            }
            while (pivot < list_of_numbers[down]) {
                down--;
            }
            if (up < down) {
                swap(list_of_numbers, up, down);
                sortedResult.setText( array_to_string(list_of_numbers));
                logger.log(Level.SEVERE, sortedResult.getText());

            }
        } while (up < down);
        swap(list_of_numbers, first, down);
        sortedResult.setText( array_to_string(list_of_numbers));

        logger.log(Level.SEVERE, sortedResult.getText());
        return down;
    }

It works really well and we can see from the logger that it puts out the following 它确实运行良好,我们可以从记录器中看到以下内容:

30, 3, 23, 7, 77, 46, 62, 91, 89, 22, 48, 96, 32, 40, 95, 
30, 3, 23, 7, 22, 46, 62, 91, 89, 77, 48, 96, 32, 40, 95, 
22, 3, 23, 7, 30, 46, 62, 91, 89, 77, 48, 96, 32, 40, 95, 
22, 3, 7, 23, 30, 46, 62, 91, 89, 77, 48, 96, 32, 40, 95, 
7, 3, 22, 23, 30, 46, 62, 91, 89, 77, 48, 96, 32, 40, 95, 
3, 7, 22, 23, 30, 46, 62, 91, 89, 77, 48, 96, 32, 40, 95, 
3, 7, 22, 23, 30, 46, 40, 91, 89, 77, 48, 96, 32, 62, 95, 
3, 7, 22, 23, 30, 46, 40, 32, 89, 77, 48, 96, 91, 62, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 89, 77, 48, 96, 91, 62, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 89, 77, 48, 96, 91, 62, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 89, 77, 48, 62, 91, 96, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 62, 77, 48, 89, 91, 96, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 62, 48, 77, 89, 91, 96, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 48, 62, 77, 89, 91, 96, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 48, 62, 77, 89, 91, 96, 95, 
3, 7, 22, 23, 30, 32, 40, 46, 48, 62, 77, 89, 91, 95, 96, 

but on the output to the screen it will only display the last iteration 但是在屏幕上的输出中,它只会显示最后一次迭代

在gui上输出

I would like to put a delay of 1 second after each sort where the user can see the current array. 我想在每次排序后放置1秒的延迟,以便用户可以看到当前数组。

I'm not sure how to use the timer in this case. 在这种情况下,我不确定如何使用计时器。 As well I don't know if it is changing the value each time so fast that I only see the last one or if it's only changing it at the end. 同样,我也不知道每次更改值的速度是否如此之快,以至于我只看到最后一个值,或者只是最后更改了它。

A quick google search yields a page guiding you through delaying calculations and updating the interface. 快速的Google搜索会产生一个页面,指导您完成延迟计算和更新界面。

You can find it here . 你可以在这里找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM