Latex & Code Sample

30. Január 2018 10:08   admin1  


Latex Example

$$ v=\left[ \begin{matrix} v_1\\ v_2 \end{matrix} \right] $$

$$ Ax = \left[ \begin{matrix} u & v & w\\ \end{matrix} \right] \left[ \begin{matrix} c\\ d\\ e\\ \end{matrix} \right] =cu+dv+ew $$

$$ \left[ \begin{matrix} v_1\\ v_2 \end{matrix} \right] \cdot \left[ \begin{matrix} w_1\\ w_2 \end{matrix} \right] = v_1w_1 + v_2w_2 $$

Code Highlight

Bubble Sort in Javascript

function bubbleSort(arr){
   var len = arr.length;
   for (var i = len-1; i>=0; i--){
     for(var j = 1; j<=i; j++){
       if(arr[j-1]>arr[j]){
           var temp = arr[j-1];
           arr[j-1] = arr[j];
           arr[j] = temp;
        }
     }
   }
   return arr;
}
bubbleSort([7,5,2,4,3,9]); //[2, 3, 4, 5, 7, 9]
bubbleSort([9,7,5,4,3,1]); //[1, 3, 4, 5, 7, 9]
bubbleSort([1,2,3,4,5,6]); //[1, 2, 3, 4, 5, 6]

Quick Sort in Python

def quicksort(x):
    if len(x) == 1 or len(x) == 0:
        return x
    else:
        pivot = x[0]
        i = 0
        for j in range(len(x)-1):
            if x[j+1] < pivot:
                x[j+1],x[i+1] = x[i+1], x[j+1]
                i += 1
        x[0],x[i] = x[i],x[0]
        first_part = quicksort(x[:i])
        second_part = quicksort(x[i+1:])
        first_part.append(x[i])
        return first_part + second_part

alist = [54,26,93,17,77,31,44,55,20]
quickSort(alist)
print(alist)

Insertion Sort in PHP

<?php

 function insertion_Sort($my_array)
{
    for($i=0;$i<count($my_array);$i++){
        $val = $my_array[$i];
        $j = $i-1;
        while($j>=0 && $my_array[$j] > $val){
            $my_array[$j+1] = $my_array[$j];
            $j--;
        }
        $my_array[$j+1] = $val;
    }
return $my_array;
}
$test_array = array(3, 0, 2, 5, -1, 4, 1);
echo "Original Array :\n";
echo implode(', ',$test_array );
echo "\nSorted Array :\n";
print_r(insertion_Sort($test_array));
?>

WAGTAIL je z anglického prekladu TRASORÍTKA
WAGTAIL DEMO FROM MICHAEL YIN, CHINA
Search