Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dvprog_19 [2021-11-30 10:07]
Daniel Viström
dvprog_19 [2024-04-12 13:45] (current)
Daniel Viström
Line 1: Line 1:
 ====== Lösningsförslag till uppgift 4 (Bubblesort) ====== ====== Lösningsförslag till uppgift 4 (Bubblesort) ======
  
-<php> 
-/* 
 Filen **bubblesort.php** \\ Filen **bubblesort.php** \\
 Jag väljer att lägga min sorteringsfunktion i en separat fil så att jag kan inkludera den i olika program utan att huvudprogrammet behöver komma med då. Jag väljer att lägga min sorteringsfunktion i en separat fil så att jag kan inkludera den i olika program utan att huvudprogrammet behöver komma med då.
Line 27: Line 25:
                 $a[$j] = $a[$j+1];                 $a[$j] = $a[$j+1];
                 $a[$j+1] = $temp;                 $a[$j+1] = $temp;
 +            }
 +            $j++;
 +        }
 +        $i++;
 +    }
 +}
 +</code>
 +
 +\\
 +**Huvudprogrammet**
 +<code php>
 +<?php
 +include 'bubblesort.php';
 +include 'head.php';
 +
 +$arr = [5,9,4,7,2,12,7,12,15];
 +my_bubblesort($arr);
 +$i = 0;
 +while($i < count($arr)){
 +    echo $arr[$i] . ' ';
 +    $i++;
 +}
 +echo '<br>';
 +
 +include 'foot.php';
 +</code>
 +
 +
 +
 +<php>
 +/*
 +<code php>
 +<?php
 +
 +function my_bubblesort(&$a){
 +    $i = 0;
 +    while ($i < count($a) - 1){
 +
 +        $j = 0;
 +        while (            ){
 +            if (            ){
 +               
 +               
             }             }
             $j++;             $j++;