-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dean
committed
May 29, 2017
0 parents
commit 4465221
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor/* | ||
composer.lock | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |