Completed
Push — development ( 68c572...497072 )
by Dylan David
01:43
created
Ptypes/DoublyLinkedList.php 1 patch
Braces   +28 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 	public $next = null, $prev = null; //A reference to the next and previous node
14 14
 	public $data = null; //Data or a reference to data
15 15
 	
16
-	public function __construct($data=null) 
16
+	public function __construct($data=null)
17 17
 	{
18 18
 		$this->data = $data;
19 19
 	}
@@ -25,13 +25,19 @@  discard block
 block discarded – undo
25 25
 	
26 26
 	private $size = 0;
27 27
 	
28
-	public function __construct() {}
28
+	public function __construct()
29
+	{
30
+}
29 31
 	
30 32
 	public function insert_after($node, $newNode)
31 33
 	{
32 34
 		//type checks
33
-		if (get_class($node) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
34
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
35
+		if (get_class($node) != "DLNode")
36
+		{
37
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
38
+		if (get_class($newNode) != "DLNode")
39
+		{
40
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
35 41
 		
36 42
 		$newNode->prev = $node;
37 43
 		if ($node->next == null)
@@ -51,8 +57,12 @@  discard block
 block discarded – undo
51 57
 	public function insert_before($node, $newNode)
52 58
 	{
53 59
 		//type checks
54
-		if (get_class($node) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
55
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
60
+		if (get_class($node) != "DLNode")
61
+		{
62
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($node)); }
63
+		if (get_class($newNode) != "DLNode")
64
+		{
65
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
56 66
 		
57 67
 		$newNode->next = $node;
58 68
 		if ($node->prev == null)
@@ -70,9 +80,11 @@  discard block
 block discarded – undo
70 80
 	}
71 81
 	
72 82
 	public function insert_beginning($newNode)
73
-	{	
83
+	{
74 84
 		//type checks
75
-		if (get_class($newNode) != "DLNode") {throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
85
+		if (get_class($newNode) != "DLNode")
86
+		{
87
+throw new InvalidArgument("Expected a DLNode, got: " . get_class($newNode)); }
76 88
 		
77 89
 		if ($this->firstNode == null)
78 90
 		{
@@ -104,13 +116,17 @@  discard block
 block discarded – undo
104 116
 	public function contains($node)
105 117
 	{
106 118
 		//check this so we could possibly avoid list traversal
107
-		if ($node == $this->firstNode || $node == $this->lastNode) {return true; }
119
+		if ($node == $this->firstNode || $node == $this->lastNode)
120
+		{
121
+return true; }
108 122
 		
109 123
 		//traverse the list and try to find the node
110 124
 		$n = $this->firstNode->next; //we can start one node ahead as we already checked the firstNode
111 125
 		while ($n != null)
112 126
 		{
113
-			if ($n == $node) {return true; }
127
+			if ($n == $node)
128
+			{
129
+return true; }
114 130
 			$n = $n->next;
115 131
 		}
116 132
 		
@@ -120,8 +136,8 @@  discard block
 block discarded – undo
120 136
 	public function remove($node)
121 137
 	{
122 138
 		//check if the node exists
123
-		if ($this->contains($node) === false) 
124
-		{ 
139
+		if ($this->contains($node) === false)
140
+		{
125 141
 			throw new InvalidArgument("The node given does not exist in this list!"); 
126 142
 		}
127 143
 		
Please login to merge, or discard this patch.