Page 72 - 《软件学报》2021年第9期
P. 72

2696                                 Journal of Software  软件学报 Vol.32, No.9,  September 2021


                                                                 public
                            1         public void bubbleSort(int array[]) {
                            2                 int t = 0           int
                            ; 3                 for (int i = 0; i < array.length - 1; i++)
                                                                  for
                             4                       for (int j = 0; j < array.length - 1 - i; j++)
                            5                             if (array[j] > array[j + 1]) {  for

                            6                                 t = array[j];
                                                                   if
                            7                                 array[j] = array[j + 1];
                                                                        null
                              8                                 array[j + 1] = t;
                            9                       }             null
                            10            }

                                  (a)  冒泡排序程序示例               (b)   关键字流图
                               Fig.2    Bubble sorting program and its keyword flow graph
                                    图 2   冒泡排序程序示例及其关键字流图


                                        1                     public
                                        2                       int
                                        3
                                                                for
                                        4                       for

                                        5                       if
                                              6                      null
                                        7                      null


                                      控制流
                                    (a)  控制流图                     (b)  关键字流图
                       Fig.3    Control flow graph and keyword flow graph of bubble sorting program
                                   图 3   冒泡排序的控制流图及其关键字流图

                                       开始                      public

                                                                int
                                      定义数组
                                                                for
                                       循环
                                                                for

                                       判断   是                    if
                                       否    转换位置                      null

                                       输出                       null
                                       结束

                                    (a)  程序流程图                   (b)  关键字流图
                       Fig.4    Program flow chart and keyword flow graph of bubble sorting program
                                   图 4   冒泡排序的程序流程图及其关键字流图
   67   68   69   70   71   72   73   74   75   76   77