예제 #1
0
<?php

$array = array(1337, 1, -465, 3.141592653589793, 789, 69, 789, -132, 3.141592653589793, 465, 789, 0, 27);
function bubblesort($array)
{
    $swapping = false;
    while (!$swapping) {
        $swapping = true;
        for ($i = 0; $i < count($array) - 1; $i++) {
            if ($array[$i] > $array[$i + 1]) {
                $temp = $array[$i + 1];
                $array[$i + 1] = $array[$i];
                $array[$i] = $temp;
                $swapping = false;
            }
        }
    }
    return $array;
}
$array = bubblesort($array);
print_r($array);
예제 #2
0
<?php

//冒泡方法
function bubblesort($num)
{
    $amount = count($num);
    //获取传入参数数量
    for ($i = 0; $i < $amount; $i++) {
        for ($j = 0; $j < $amount - $i - 1; $j++) {
            if ($num[$j] > $num[$j + 1]) {
                //与后一位比较 大者下沉
                $temp = $num[$j];
                $num[$j] = $num[$j + 1];
                $num[$j + 1] = $temp;
            }
        }
    }
    return $num;
}
$num = array(1, 4, 6, 2, 8, 5, 3, 7, 9);
var_dump(bubblesort($num));
 */
$data = array(8, 4, 1, 9, 5, 7, 3, 2, 6, 0);
/**
 * ############################################################################
 * The nitty gritty
 */
function bubblesort($data)
{
    $data_length = count($data);
    for ($i = 0; $i < $data_length; $i++) {
        for ($j = 0; $j < $data_length - 1 - $i; $j++) {
            if ($data[$j + 1] < $data[$j]) {
                $data = swappositions($data, $j, $j + 1);
            }
        }
    }
    return $data;
}
$data = bubblesort($data);
print_r($data);
/**
 * ############################################################################
 * Our toolbelt
 */
function swappositions($data, $left, $right)
{
    $backup_old_data_right_value = $data[$right];
    $data[$right] = $data[$left];
    $data[$left] = $backup_old_data_right_value;
    return $data;
}
예제 #4
0
if (isset($auth) && !empty($auth->auth["perm"])) {
    page_close();
    page_open(array("sess" => "SourceAgency_Session", "auth" => "SourceAgency_Auth", "perm" => "SourceAgency_Perm"));
}
require "include/header.inc";
require "include/historylib.inc";
$bx = new box("100%", $th_box_frame_color, $th_box_frame_width, $th_box_title_bgcolor, $th_box_title_font_color, $th_box_title_align, $th_box_body_bgcolor, $th_box_body_font_color, $th_box_body_align);
start_content();
$page = "history";
if (check_proid($proid)) {
    top_bar($proid, $page);
    htmlp_image("ic/e.png", 0, 60, 51, "Summary");
    print $t->translate('This is the chronological list of all the actions ' . 'that have affected the current project') . ".<p>\n";
    $i = 0;
    history_extract_table("description", "description_creation", "description_user", "project_title");
    history_extract_table("consultants", "creation", "consultant", "Consultant offered");
    history_extract_table("comments", "creation_cmt", "user_cmt", "subject_cmt");
    history_extract_table("news", "creation_news", "user_news", "subject_news");
    history_extract_table("tech_content", "creation", "content_user", "Content proposed");
    history_extract_table("history", "creation", "history_user", "action");
    history_extract_table("developing", "creation", "developer", "Developing Proposal");
    history_extract_table("sponsoring", "creation", "sponsor", "Sponsoring wish");
    history_extract_table("milestones", "creation", "milestone_user", "product");
    history_extract_table("referees", "creation", "referee", "Referee offered");
    bubblesort($history);
    show_history($history);
    lib_comment_it($proid, 'General', '0', '0', 'Comment on the Project History', $t->translate('General Comments'));
}
end_content();
require "include/footer.inc";
@page_close();