localheinz/data-structure

Provides implementations of data structures.

dev-master 2017-09-20 15:20 UTC

README

Build Status Code Climate Test Coverage Issue Count Latest Stable Version Total Downloads

This package provides implementations of data structures.

Installation

Run

$ composer require localheinz/data-structure

Data Structures

  • Localheinz\DataStructure\Queue
  • Localheinz\DataStructure\Stack

Queue

use Localheinz\DataStructure\Queue;

$queue = new Queue();

$queue->isEmpty(); // true
$queue->isFull(); // false

$queue->enqueue('foo');
$queue->enqueue('bar');
$queue->isEmpty(); // false
$queue->isFull(); // false

$queue->dequeue(); // 'foo'
$queue->dequeue(); // 'bar'
$queue->isEmpty(); // true
$queue->isFull(); // false

$maxSize = 1;

$anotherQueue = new Queue($maxSize);

$anotherQueue->enqueue('foo');
$anotherQueue->isFull(); // true

Stack

use Localheinz\DataStructure\Stack;

$stack = new Stack();

$stack->isEmpty(); // true
$stack->isFull(); // false

$stack->push('foo');
$stack->push('bar');
$stack->isEmpty(); // false
$stack->isFull(); // false

$stack->peek(); // 'bar'

$stack->pop(); // 'bar'
$stack->pop(); // 'foo'
$stack->isEmpty(); // true
$stack->isFull(); // false

$maxSize = 1;

$anotherStack = new Stack($maxSize);

$anotherStack->push('foo');
$anotherStack->isFull(); // true

Contributing

Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.