Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- adott kettő tömb: [1,3,5,7] és [2,4,6,8]
- mindkettő tömb sorrendezve van
- írj egy olyan függvényt amely kimenetén az összefűzött tömb van
- ne használd az array_merge és sort függvényt!
- <?php
- $testcases = [
- '[1] + [2]' => [
- [ [1],[2] ],
- [1,2]
- ],
- '[2] + [1]' => [
- [ [2],[1] ],
- [1,2]
- ],
- '[1,2] + [3,4]' => [
- [ [1,2],[3,4] ],
- [1,2,3,4]
- ],
- '[3,4] + [1,2]' => [
- [ [3,4],[1,2] ],
- [1,2,3,4]
- ],
- '[1,2,3,4] + [5,6,7,8]' => [
- [ [1,2,3,4],[5,6,7,8] ],
- [1,2,3,4,5,6,7,8]
- ],
- '[5,6,7,8] + [1,2,3,4]' => [
- [ [5,6,7,8],[1,2,3,4] ],
- [1,2,3,4,5,6,7,8]
- ],
- '[1,3,5,7] + [2,4,6,8]' => [
- [ [1,3,5,7],[2,4,6,8] ],
- [1,2,3,4,5,6,7,8]
- ],
- '[2,4,6,8] + [1,3,5,7]' => [
- [ [2,4,6,8],[1,3,5,7] ],
- [1,2,3,4,5,6,7,8]
- ],
- '[1,2,3] + [4,5,6,7,8,9]' => [
- [ [1,2,3],[4,5,6,7,8,9] ],
- [1,2,3,4,5,6,7,8,9]
- ],
- '[1,2,3,4,5,6] + [7,8,9]' => [
- [ [1,2,3,4,5,6],[7,8,9] ],
- [1,2,3,4,5,6,7,8,9]
- ],
- '[1,3,5] + [2,4,6,7,8,9]' => [
- [ [1,3,5],[2,4,6,7,8,9] ],
- [1,2,3,4,5,6,7,8,9]
- ],
- '[1,2,3,4,6,8] + [5,7,9]' => [
- [ [1,2,3,4,6,8],[5,7,9] ],
- [1,2,3,4,5,6,7,8,9]
- ],
- ];
- foreach($testcases as $caseName => $case)
- {
- echo "$caseName => ";
- $result = merge_sorted_array(...$case[0]);
- if ($result === $case[1]) echo "Átment" . PHP_EOL;
- else echo "Hibás" . PHP_EOL;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement