延迟计时器在gwt上快速排序

时间:2018-05-17 10:37:03

标签: java gwt delay

我正在GWT中编写快速排序算法,在每次迭代之间,我正在尝试打印当前状态。

这是方法

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

它的效果非常好,我们可以从记录器中看到它发出以下内容

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, 

但是在屏幕输出上它只显示最后一次迭代

output on gui

我希望在每次排序后延迟1秒,用户可以看到当前数组。

在这种情况下,我不确定如何使用计时器。我也不知道它是否每次都如此快地改变价值,以至于我只看到最后一个或者它只是在最后改变它。

1 个答案:

答案 0 :(得分:0)

快速谷歌搜索会产生一个页面,引导您推迟计算和更新界面。

你可以找到它here