Skip to content

Instantly share code, notes, and snippets.

@clausjoergensen
Created July 25, 2011 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clausjoergensen/1103488 to your computer and use it in GitHub Desktop.
Save clausjoergensen/1103488 to your computer and use it in GitHub Desktop.
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