Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dean committed May 29, 2017
0 parents commit 4465221
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/*
composer.lock
.idea/*
14 changes: 14 additions & 0 deletions Test/TestStack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: dean
* Date: 27/05/17
* Time: 10:18
*/

use PHPUnit\Framework\TestCase;

class TestStack extends TestCase
{

}
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"autoload" : {
"psr-4" : {
"App\\" : "src"
}
},
"require-dev": {
"phpunit/phpunit": "~5.7.17",
"php" : "5.6.30"
}
}
21 changes: 21 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use App\stack;

require "vendor/autoload.php";

$stack = new \App\stack();

$stack->add('123');
$stack->add('abc');
$stack->add('555');

print_r($stack);
print_r($stack->remove());
print_r($stack->remove());
print_r($stack);

$stack->add('new wave');
print_r($stack);


72 changes: 72 additions & 0 deletions src/stack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Author: Dean Haines
* Date: 27/05/17
*/

namespace App;

use App\stackNode;

/**
* Class stack
* @package App
*/
class stack
{

protected $count;
protected $list;


/**
* stack constructor.
*/
public function __construct()
{
$this->list = [];
$this->count = 0;
}

/**
* @param $data
*/
public function add($data)
{
$item = new stackNode($data);
$this->insert($item);

}

/**
* @param \App\stackNode $item
*/
protected function insert(stackNode $item)
{
array_push($this->list,$item);
$this->count++;
}


/**
* @return int
*/
public function getCount()
{
return $this->count;
}

/**
* @return mixed
*/
public function remove()
{
$temp = $this->list[0];
unset($this->list[0]);
$this->list = array_values($this->list);

$this->count--;
return $temp;
}

}
26 changes: 26 additions & 0 deletions src/stackNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: dean
* Date: 27/05/17
* Time: 09:44
*/

namespace App;


class stackNode
{

protected $item;

/**
* stackNode constructor.
* @param $item
*/
public function __construct($item)
{
$this->item = $item;
return $this->item;
}
}

0 comments on commit 4465221

Please sign in to comment.