Пример #1
0
function main()
{
    $a = f();
    echo "writing: ";
    echo $a[1] = 66;
    echo "\n";
    echo "reading: ";
    echo $a[1];
    echo "\n";
    populateArray(1000);
}
Пример #2
0
 if (is_numeric($_POST["lng"]) && is_numeric($_POST["lat"]) && is_numeric($_POST["rad"])) {
     $long = $_POST["lng"];
     $lat = $_POST["lat"];
     $radius = abs($_POST["rad"]);
     try {
         $conn = db2_connect($database, $user, $pass);
     } catch (Exception $e) {
         exit;
         //echo "Exception: ". $e->getMessage();
     }
     $sqlInitialize = "set current function path = current function path, db2gse";
     $sqlQuery = "select * from emmanuel.restaurant where st_distance(location,st_point(" . $long . ", " . $lat . ",1), 'STATUTE MILE') < " . $radius;
     $dataDump = array();
     if ($conn) {
         db2_exec($conn, $sqlInitialize);
         populateArray($sqlQuery, $conn, $dataDump);
         $results['results'] = $dataDump;
         db2_close($conn);
         echo json_encode($results);
     } else {
         $f['status'] = "0";
         $f['msg'] = "Unable to connect to database.";
         $results['results'] = $f;
         echo json_encode($results);
         //echo db2_conn_error()."<br>";
         //echo db2_conn_errormsg()."<br>";
         //echo "Connection failed.<br>";
     }
 } else {
     $f['status'] = "0";
     $f['msg'] = "Invalid Parameters detected.";
Пример #3
0
    } else {
        $sorted = insertionSort($arr, $maxIndex, $iteration + 1);
        $element = $arr[$iteration];
        // All elements to the right of index $i are assumed to be sorted.
        // Now we just have to figure out where $el fits in the sorted array
        for ($i = $iteration + 1; $i < $maxIndex; $i++) {
            if ($element > $sorted[$i]) {
                // $el is bigger, swap so $el moves to the right in the array.
                $sorted[$i - 1] = $sorted[$i];
                $sorted[$i] = $element;
            }
        }
        // echo "<h1>Iteration ".$iteration."</h1>";
        // echo var_dump($sorted);
        return $sorted;
    }
}
function populateArray($arr)
{
    for ($i = 0; $i < 10; $i++) {
        $num = rand(0, 100);
        array_push($arr, $num);
    }
    return $arr;
}
$arr = array();
$arr = populateArray($arr);
$sorted = insertionSort($arr, count($arr), 0);
echo var_dump($arr);
echo "<br>";
echo var_dump($sorted);
Пример #4
0
    if ($length <= 1) {
        return $array;
    } else {
        // select the last item to act as our pivot point
        $pivot = $array[$length - 1];
        // declare our two arrays to act as partitions
        $left = array();
        $right = array();
        // loop and compare each item in the array to the pivot value, place item in appropriate partition
        for ($i = 0; $i < $length - 1; $i++) {
            if ($array[$i] < $pivot) {
                $left[] = $array[$i];
            } else {
                $right[] = $array[$i];
            }
        }
        // use recursion to now sort the left and right lists
        return array_merge(quicksort($left), array($pivot), quicksort($right));
    }
}
function populateArray()
{
    $arr = array();
    for ($i = 0; $i < 10; $i++) {
        $num = rand(0, 1000);
        array_push($arr, $num);
    }
    return $arr;
}
var_dump(quicksort(populateArray()));
<?php

include_once 'connect.php';
$toppings = array();
$items = array();
$dorms = array();
$specCosts = array();
populateArray(mysqli_query($GLOBALS["conn"], "SELECT toppingId, name FROM Toppings"), $toppings);
populateArray(mysqli_query($GLOBALS["conn"], "SELECT itemId, name, cost FROM Items"), $items);
populateArray(mysqli_query($GLOBALS["conn"], "SELECT hallId, name FROM ResidenceHall WHERE hallId != 1"), $dorms);
populateArray(mysqli_query($GLOBALS["conn"], "SELECT cost, name FROM Pizza WHERE pizzaId < 10 AND pizzaId > 1"), $specCosts);
function populateArray($query, &$array)
{
    while ($value = mysqli_fetch_array($query)) {
        $array[] = $value;
    }
}
?>

<script>
    var moreTop  = <?php 
echo json_encode($toppings);
?>
;
    var items =  <?php 
echo json_encode($items);
?>
;
    var dorms = <?php 
echo json_encode($dorms);
?>
Пример #6
0
    $result = array();
    while (count($left) > 0 && count($right) > 0) {
        if ($left[0] > $right[0]) {
            $result[] = $right[0];
            $right = array_slice($right, 1);
        } else {
            $result[] = $left[0];
            $left = array_slice($left, 1);
        }
    }
    while (count($left) > 0) {
        $result[] = $left[0];
        $left = array_slice($left, 1);
    }
    while (count($right) > 0) {
        $result[] = $right[0];
        $right = array_slice($right, 1);
    }
    return $result;
}
function populateArray()
{
    $arr = array();
    for ($i = 0; $i < 10; $i++) {
        $num = rand(0, 1000);
        array_push($arr, $num);
    }
    return $arr;
}
var_dump(mergesort(populateArray()));
Пример #7
0
            if ($number[$maxDigits - 1 - $i] == 0) {
                //put it in the 0 bucket
                array_push($buckets[0], $arr[$j]);
                //else it is a 1
            } else {
                //put it in the 1 bucket
                array_push($buckets[1], $arr[$j]);
            }
        }
        //resort into our array
        $k = 0;
        foreach ($buckets as $bucket) {
            foreach ($bucket as $value) {
                $arr[$k] = $value;
                $k++;
            }
        }
    }
    return $arr;
}
$arr = populateArray();
$time_start = microtime_float();
radixSort($arr);
$time_end = microtime_float();
echo "<h1>Regular Radix Sort</h1>";
echo $time_end - $time_start . "<br>";
$time_start = microtime_float();
binaryRadixSort($arr);
$time_end = microtime_float();
echo "<h1>Binary Radix Sort</h1>";
echo $time_end - $time_start;