Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body>
- <form method="POST" active="" align="center">
- <div>Enter number:</div><input class="textplace" name="num" type="number">
- <input type="submit" name="show">
- </form>
- <?php
- if(isset($_POST["show"])){
- $array = array();
- $size = $_POST['num'];
- for($i = 0; $i < $size; $i++){
- $array[$i] = rand(1, 100);
- }
- function insertSort(array &$array)
- {
- for($j=1;$j<$size;$j++){
- $key = $array[$j];
- $i=$j-1;
- while($i>=0 && $array[$i]>$key){
- $array[$i+1]=$array[$i];
- $array[$i]=$key;
- $i--;
- }
- }
- }
- // $arr[$i] = rand(1, 100);
- // }
- // function bubble_sort($arr) {
- // $size = count($arr);
- // for ($i=0; $i<$size; $i++) {
- // for ($j=0; $j<$size-1-$i; $j++) {
- // if ($arr[$j+1] < $arr[$j]) {
- // swap($arr, $j, $j+1);
- // }
- // }
- // }
- // return $arr;
- // }
- // function swap(&$arr, $a, $b) {
- // $tmp = $arr[$a];
- // $arr[$a] = $arr[$b];
- // $arr[$b] = $tmp;
- // }
- print("<b>Before sorting: </b><br>");
- for($i = 0; $i < $_POST['num']; $i++){ echo " ➝ ".$array[$i]; }
- $time_start = microtime(true);
- $array = insertSort($array);
- $time_end = microtime(true);
- $execution_time = ($time_end - $time_start);
- echo '<b><br>Total Execution Time:</b> '.$execution_time.' Secs <br>';
- print("<b>After sorting: </b><br>");
- for($i = 0; $i < $_POST['num']; $i++){ echo " ➝ ".$array[$i];}
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement