Created
July 25, 2011 03:06
-
-
Save clausjoergensen/1103488 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
open System | |
type Node<'T>(nodeValue : 'T, next : Node<'T> option) = | |
member this.NodeValue | |
with get() = | |
nodeValue | |
member this.Next | |
with get() = | |
next | |
type LinkedList<'T>() = | |
let mutable head = Option<Node<'T>>.None | |
let rec printList (node : Node<'T> option) = | |
match node with | |
| None -> None | |
| Some(value) -> | |
printfn "%A" value.NodeValue | |
match value.Next with | |
| None -> None | |
| Some(nextNode) -> printList(Some nextNode) | |
member this.Insert(value) = | |
let nextNode = new Node<'T>(value, head) | |
head <- Some nextNode | |
member this.PrintList() = | |
printList(head) | |
let list = new LinkedList<string>() | |
list.Insert("foo") | |
list.Insert("bar") | |
list.Insert("bas") | |
list.PrintList() |> ignore | |
Console.Read() |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment