Advertisement
Guest User

Untitled

a guest
May 28th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.79 KB | None | 0 0
  1.     // Stack type.
  2.     type Stack() =
  3.  
  4.         // Private mutable list.
  5.         let mutable stack = []
  6.  
  7.         // Pushing one element.
  8.         member this.Push element =
  9.             stack <- element::stack
  10.  
  11.         // Popping element.
  12.         // If there are elements in stack we return
  13.         // top element and rest of a stack.
  14.         member this.Pop =
  15.             match stack with
  16.             | top::rest ->
  17.                 stack <- rest
  18.                 (top, stack)
  19.             | [] -> failwith "Stack underflow"
  20.  
  21.         // If stack is empty.
  22.         member this.IsEmpty =
  23.             match stack with
  24.             | [] ->
  25.                 true
  26.             | _ ->
  27.                 false
  28.  
  29.         // Getting stack.
  30.         member this.GetStack() =
  31.             stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement