Advertisement
koki2000

házi feladat

Oct 16th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1. adott kettő tömb: [1,3,5,7] és [2,4,6,8]
  2. mindkettő tömb sorrendezve van
  3. írj egy olyan függvényt amely kimenetén az összefűzött tömb van
  4. ne használd az array_merge és sort függvényt!
  5.  
  6. <?php
  7. $testcases = [
  8.     '[1] + [2]' => [
  9.                 [ [1],[2] ],
  10.                 [1,2]
  11.             ],
  12.             '[2] + [1]' => [
  13.                 [ [2],[1] ],
  14.                 [1,2]
  15.             ],
  16.             '[1,2] + [3,4]' => [
  17.                 [ [1,2],[3,4] ],
  18.                 [1,2,3,4]
  19.             ],
  20.             '[3,4] + [1,2]' => [
  21.                 [ [3,4],[1,2] ],
  22.                 [1,2,3,4]
  23.             ],
  24.             '[1,2,3,4] + [5,6,7,8]' => [
  25.                 [ [1,2,3,4],[5,6,7,8] ],
  26.                 [1,2,3,4,5,6,7,8]
  27.             ],
  28.             '[5,6,7,8] + [1,2,3,4]' => [
  29.                 [ [5,6,7,8],[1,2,3,4] ],
  30.                 [1,2,3,4,5,6,7,8]
  31.             ],
  32.             '[1,3,5,7] + [2,4,6,8]' => [
  33.                 [ [1,3,5,7],[2,4,6,8] ],
  34.                 [1,2,3,4,5,6,7,8]
  35.             ],
  36.             '[2,4,6,8] + [1,3,5,7]' => [
  37.                 [ [2,4,6,8],[1,3,5,7] ],
  38.                 [1,2,3,4,5,6,7,8]
  39.             ],
  40.             '[1,2,3] + [4,5,6,7,8,9]' => [
  41.                 [ [1,2,3],[4,5,6,7,8,9] ],
  42.                 [1,2,3,4,5,6,7,8,9]
  43.             ],
  44.             '[1,2,3,4,5,6] + [7,8,9]' => [
  45.                 [ [1,2,3,4,5,6],[7,8,9] ],
  46.                 [1,2,3,4,5,6,7,8,9]
  47.             ],
  48.             '[1,3,5] + [2,4,6,7,8,9]' => [
  49.                 [ [1,3,5],[2,4,6,7,8,9] ],
  50.                 [1,2,3,4,5,6,7,8,9]
  51.             ],
  52.             '[1,2,3,4,6,8] + [5,7,9]' => [
  53.                 [ [1,2,3,4,6,8],[5,7,9] ],
  54.                 [1,2,3,4,5,6,7,8,9]
  55.             ],
  56. ];
  57.  
  58. foreach($testcases as $caseName => $case)
  59. {
  60.     echo "$caseName => ";
  61.     $result = merge_sorted_array(...$case[0]);
  62.     if ($result === $case[1]) echo "Átment" . PHP_EOL;
  63.     else echo "Hibás" . PHP_EOL;
  64. }
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement