Pārlūkot izejas kodu

Add some more functionality to TLinkedList.

Carl Husberg 3 gadi atpakaļ
vecāks
revīzija
33d8d65621
1 mainītis faili ar 40 papildinājumiem un 0 dzēšanām
  1. 40 0
      collections.mod/linkedlist.bmx

+ 40 - 0
collections.mod/linkedlist.bmx

@@ -76,6 +76,46 @@ Public
 		End If
 		End If
 	End Method
 	End Method
 	
 	
+	Rem
+	bbdoc: Gets the first value of the #TLinkedList.
+	End Rem
+	Method FirstValue:T()
+		If head Then
+			Return head.value
+		Else
+			Return Null
+		EndIf
+	EndMethod
+	
+	Rem
+	bbdoc: Gets the last value of the #TLinkedList.
+	End Rem
+	Method LastValue:T()
+		If head Then
+			Return head.PreviousNode.value
+		Else
+			Return Null
+		EndIf
+	EndMethod
+	
+	Rem
+	bbdoc: Removes the first value of the #TLinkedList and returns it.
+	EndRem
+	Method Shift:T()
+		Local val:T = FirstValue()
+		RemoveFirst()
+		Return val
+	EndMethod
+	
+	Rem
+	bbdoc: Removes the last value of the #TLinkedList and returns it.
+	EndRem
+	Method Pop:T()
+		Local val:T = LastValue()
+		RemoveLast()
+		Return val
+	EndMethod
+	
 	Rem
 	Rem
 	bbdoc: Adds a new node containing the specified @value after the specified existing @node in the #TLinkedList.
 	bbdoc: Adds a new node containing the specified @value after the specified existing @node in the #TLinkedList.
 	returns: The new node.
 	returns: The new node.