冒泡排序在PB中的实现

    技术2022-05-11  20

     冒泡排序主要是用于把一组数据进行排序,在pb中函数方式实现如下():

    /*-----------------------------------------------------------------------------------------------

    Funtion Name:f_sort()

    Argument: integer test[]

    returnvalue string

    ------------------------------------------------------------------------------------------------*/

    integer i,j,li_temp,li_sumnum

    string ls_return

    li_sumnum = upperbound(test[])

    if li_sumnum = 0 then return ''

    //进行li_sumnum-i趟排序

    for i = 1 to li_sumnum 

    //每趟要进行li_sumnum-i次比较

    for j = i+1 to li_summun

    if a[i]> a[j] then

    li_temp = a[i]

    a[i] =a[j]

    a[j] =li_temp

    end if

    next

    next

    for i  = 1 to li_sumnum

    if i = 1 then

    ls_return = a[i]

    else

    ls_return = ls_return ','+a[i]

    end if

    next

    return ls_return


    最新回复(0)