rafayrty/linkedlist-php

此包允许您在PHP项目中使用链表,当在数组开头插入元素实际成本较高时非常有用。

dev-main 2023-07-03 00:49 UTC

README

一个PHP包,实现链表功能,适用于在数组开头插入元素成本较高的情况。

安装

您可以通过composer安装此包

composer require rafayrty/linkedlist-php

使用方法

$list = new Rafayrty\LinkedListPhp\SinglyList();
//Insert a New Node to the LinkedList
$list->push(5); // -> returns the linkedlist

//Remove the Last Node from the LinkedList
$list->pop(); // -> returns value of deleted element

//Remove the Initial Node from the LinkedList
$list->shift(); // -> returns value of deleted node

//Add a Node To Beginning of the LinkedList
$list->unshift(5); // -> returns the linkedlist

//Get a Node from a specific index 
$list->get(0); // -> returns the value of the node

//Remove a Node from a specific index 
$list->remove(0); // -> returns the value of the deleted node

//Convert Your LinkedList to an array
$list->toArray(); // -> returns an array of linkedlist

//Delete an Element from a specified index to deleteCount similar to JS array splice
$list->splice($starting,$deletecount); // -> returns the linkedlist

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 变更日志

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅 许可证文件