Advertisement
Guest User

Untitled

a guest
Jun 1st, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. trait Sorting {
  6.     abstract public function Comparable($x,$y);
  7.  
  8.     function isSorted($object): bool
  9.     {
  10.         $sortedL = false;
  11.         for ($i = 0; $i < count($object)-1; $i++) {
  12.             if ($object->Comparable($object[$i+1],$object[$i])){
  13.                $sortedL= true;
  14.             }
  15.             else{
  16.                 $sortedL= false;
  17.             }
  18.  
  19.         }
  20.         return $sortedL;
  21.     }
  22.  
  23. }
  24.  
  25. class Sortingclass{
  26.     use Sorting;
  27.     public function Comparable($x,$y)
  28.     {
  29.         if($x < $y){
  30.             return -1;
  31.         }
  32.         else{
  33.             return 1;
  34.         }
  35.     }
  36.  
  37.  
  38.  
  39. }
  40.  
  41. $class1 = new Sortingclass;
  42. $info = array(1,2,3,4,5);
  43. $sort = $class1->isSorted($info);
  44. echo $sort;
  45.  
  46.  
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement