started implementation

This commit is contained in:
Johannes Schmelz 2024-03-01 23:37:35 +01:00
parent 81f4e2d2ec
commit 98368e8913
2 changed files with 24 additions and 3 deletions

View File

@ -18,6 +18,7 @@ object REPL:
def repl(endState: GameState): Unit = def repl(endState: GameState): Unit =
while gs != endState while gs != endState
do do
??? ???
/** /**

View File

@ -17,7 +17,10 @@ object SimpleList:
* @param list the list * @param list the list
* @param item append this item * @param item append this item
*/ */
def append[A](list: SimpleList[A], item: A): Unit = ??? def append[A](list: SimpleList[A], item: A): Unit = {
var l = SimpleList(item, list)
return l
}
/** /**
* Determines the length of the SimpleList. * Determines the length of the SimpleList.
@ -25,7 +28,15 @@ object SimpleList:
* @param list the list * @param list the list
* @return the length * @return the length
*/ */
def length[A](list: SimpleList[A]): Int = ??? def length[A](list: SimpleList[A]): Int = {
var l = list
var counter: Int = 0
while l != null do {
counter = counter + 1
l = l.next
}
return counter
}
/** /**
* Tests if the SimpleList contains a given element. * Tests if the SimpleList contains a given element.
@ -36,4 +47,13 @@ object SimpleList:
* @param item search for this item * @param item search for this item
* @return true if the SimpleList contains the item, false if not * @return true if the SimpleList contains the item, false if not
*/ */
def contains[A](list: SimpleList[A], item: A): Boolean = ??? def contains[A](list: SimpleList[A], item: A): Boolean = {
var l = list
while l != null do {
if (l.entry == item) then {
return true
}
l = l.next
}
return false
}