SPL-翻译

public void add ( mixed $index , mixed $newval )
— Add/insert a new value at the specified index
—添加或插入一个新的节点到链表的指定位置
 
public mixed bottom ( void )
— Peeks at the node from the beginning of the doubly linked list
— 获取双向链表的第一个节点(第一个添加的节点)
 
public int count ( void )
— Counts the number of elements in the doubly linked list.
—计算当前双向链表的节点数
 
public mixed current ( void )
— Return current array entry
—获取当前指针指向的节点
 
public int getIteratorMode ( void )
— Returns the mode of iteration
—返回迭代器的模式
 
public bool isEmpty ( void )
— Checks whether the doubly linked list is empty.
—检查双向链表的是否为空
 
public mixed key ( void )
— Return current node index
— 获取当前指针指向的节点的位置
 
public void next ( void )
— Move to next entry
— 将当前指针移动至下一个节点

public bool offsetExists ( mixed $index )
— Returns whether the requested $index exists
— 判断指定位置的节点是否存在
 
public mixed offsetGet ( mixed $index )
— Returns the value at the specified $index
— 获取指定位置的节点
 
public void offsetSet ( mixed $index , mixed $newval )
— Sets the value at the specified $index to $newval
— 替换掉指定位置的节点(必须是存在的节点才能被替换)
 
public void offsetUnset ( mixed $index )
— Unsets the value at the specified $index
— 删除指定位置的节点
 
public mixed pop ( void )
— Pops a node from the end of the doubly linked list
 
public void prev ( void )
— Move to previous entry
 
public void push ( mixed $value )
— Pushes an element at the end of the doubly linked list
 
public void rewind ( void )
— Rewind iterator back to the start
 
public string serialize ( void )
— Serializes the storage
 
public void setIteratorMode ( int $mode )
— Sets the mode of iteration
 
public mixed shift ( void )
— Shifts a node from the beginning of the doubly linked list
 
public mixed top ( void )
— Peeks at the node from the end of the doubly linked list
 
ublic void unserialize ( string $serialized )
— Unserializes the storage
 
public void unshift ( mixed $value )
— Prepends the doubly linked list with an element
 
public bool valid ( void )
— Check whether the doubly linked list contains more nodes
 
当链表指针指向的节点被删除之后,链表指针就失去指向的焦点。
 
数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合。解决的是软件开发过程中数据如何存储和表示的问题
链表的基本概念
节点:
链表指针:是当前关注的节点的标识可以指向任意节点
当前节点:链表指针指向的节点
bottom :最先加入链表的节点称叫做bottom(底部),同时也成为头部(head)
top :最后加入链表的节点称叫做top(顶部),同时也成为尾部
节点的基本概念
节点名称:可以在链表中唯一标识一个节点的名称,我们通常又称为节点的key或者offset
节点数据:存放在链表中的应用数据,我们通常称为value

 SPL是什么?是一个解决common problem的一个标准的php函数库。

什么是common problem?数据结构/数据建模(数据存储)、元素遍历(数据查看)、常用方法的统一调用、类定义在自动加载等.....

数据与链表的区别

  • 数组是将元素在内存中连续存放,由于每个元素占用内存相同,可以通过下标迅速访问数组中任何元素。但是如果要在数组中增加一个元素,需要移动大量元素,在内存中空出一个元素的空间,然后将要增加的元素放在其中。同样的道理,如果想删除一个元素,同样需要移动大量元素去填掉被移动的元素。如果应用需要快速访问数据,很少或不插入和删除元素,就应该用数组。
  • 链表恰好相反,链表中的元素在内存中不是顺序存储的,而是通过存在元素中的指针联系到一起。比如:上一个元素有个指针指到下一个元素,以此类推,直到最后一个元素。如果要访问链表中一个元素,需要从第一个元素开始,一直找到需要的元素位置。但是增加和删除一个元素对于链表数据结构就非常简单了,只要修改元素中的指针就可以了。如果应用需要经常插入和删除元素你就需要用链表数据结构了。

    (1) 从逻辑结构角度来看
      a, 数组必须事先定义固定的长度(元素个数),不能适应数据动态地增减的情况。当数据增加时,可能超出原先定义的元素个数;当数据减少时,造成内存浪费。
      b,链表动态地进行存储分配,可以适应数据动态地增减的情况,且可以方便地插入、删除数据项。(数组中插入、删除数据项时,需要移动其它数据项)
    (2)从内存存储角度来看
      a,(静态)数组从栈中分配空间, 对于程序员方便快速,但自由度小。
      b, 链表从堆中分配空间, 自由度大但申请管理比较麻烦.

 

posted @ 2015-12-05 23:12  doxob  阅读(153)  评论(0)    收藏  举报