1、特征的每个节点以key-value的形式存储2、时间复杂度操作时间复杂度AddO(1)UpdateO(n)DeleteO(n)QueryO(n)3、Code节点CodesetTail($tail)->setKey($key)->setValue($value);}/***设置尾节点*@paramNode|null$tail*@return$this*/publicfunctionsetTail(?Node$tail):self{$this->tail=$tail;返回$这个;}/***获取尾节点*@returnNode|null*/publicfunctiongetTail():?Node{return$this->tail;}/***设置密钥*@paramstring|int$key*@return$this*/publicfunctionsetKey($key):self{$this->key=$key;返回$这个;}/***获取节点中的键*@returnmixed*/publicfunctiongetKey(){return$this->key;}/***设置值*@parammixed$value*@return$this*/publicfunctionsetValue($value):self{$this->value=$value;返回$这个;}/***获取节点中的值*@returnmixed*/publicfunctiongetValue(){return$this->value;}}图的代码node=null;$this->size=0;}/***获取集合中的元素*@returnint*/publicfunctiongetSize():int{return$this->size;}/***查询值是否存在Node*@param$key*@returnNode|null*/publicfunctioncontains($key):?Node{$node=$this->node;while(!is_null($node)){if($node->getKey()===$key){返回$node;}$node=$node->getTail();}返回空值;}/***插入*@paramstring|int$key*@returnNode*@throws\Exception*/publicfunctionadd($key):?Node{if(is_null($this->contains($key))){//添加新的$newNode=newNode($key,1,null);$newNode->setTail($this->node);$this->node=$newNode;$这个->尺寸++;返回$新节点;}else{//在基础上自增$node=$this->node;while(!is_null($node)){if($node->getKey()==$key){$node->setValue($node->getValue()+1);返回$节点;}}}返回空值;}/***delete*@param$key*/publicfunctionremove($key){//returnif(is_null($this->node))return;//如果删除第一个节点if($this->node->getKey()==$key){$this->node=$this->node->getTail();$this->大小--;返回;}//删除第二个及之后的节点$node=$this->node;while(!is_null($node->getTail())){if($node->getTail()->getKey()===$key){$node->setTail($node->getTail()->getTail());$这个->大小--;返回;}$node=$node->getTail();}返回;}publicfunctionvarDump(){$node=$this->node;while(!is_null($node)){echo$node->getKey().“>>”。$node->getValue().PHP_EOL;$节点=$节点->getTail();}}}4。示例add($map->add('a');$map->add('c');$map->add('c');$map->add('d');$map->add('d');$map->add('b');$map->add('b');//删除节点$map->remove('b');//打印$map->varDump();d>>2c>>2a>>2
