sele 发表于 2017-3-3 11:07:08

php Arraylist

  <?php
  class ArrayList {
 var $elementData = array ();
 var $size = 0;
 function ArrayList() {
 }
 
 function add($element) {
  $this->elementData [$this->size] = $element;
  $this->size ++;
 }
 
 function get($index) {
  if ($this->rangeCheck ( $index )) {
   return $this->elementData [$index];
  }
 }
 
 function remove($index) {
  if ($this->rangeCheck ( $index )) {
   for($i = $index; $i < $this->size; $i ++) {
    $this->elementData [$i] = $this->elementData [$i + 1];
   }
   $this->size --;
   return true;
  }
  return false;
 }
 
 function rangeCheck($index) {
  if ($index < $this->size)
   return true;
  return false;
 }
 
 function size() {
  return $this->size;
 }
 
 function clear() {
  for($i = 0; $i < $this->size; $i ++) {
   $this->element [$i] = " ";
  }
  $this->size = 0;
 }
 
 function isEmpty() {
  return $this->size == 0;
 }
}
  ?>
页: [1]
查看完整版本: php Arraylist