Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 0.73 KB | None | 0 0
  1. %SEQUENCE
  2. attr x
  3. meth init x:=nil end
  4. meth isEmpty($) @x==nil end
  5. meth first($) @x.1 end
  6. meth last($) {Nth @x {Length @x}} end
  7. meth insertFirst(X) x:= X|@x end
  8. meth insertLast(X) x:={Append @x X|nil} end
  9. meth removeFirst x:=@x.2 end
  10. meth removeLast
  11.     local L in
  12.         L=@x
  13.         x:=nil
  14.         for I in {Length L}-1..1;~1 do
  15.             x:= {Nth L I}|@x
  16.         end
  17.     end
  18. end
  19.  
  20. %PALINDROME
  21. S={New Sequence init}
  22.     fun{Check}
  23.         if {S isEmpty($)} then true
  24.         else
  25.             if {S first($)}=={S last($)} then
  26.             {S removeFirst}
  27.             {S removeLast}
  28.             {Check}
  29.             else false end
  30.         end
  31.     end
  32. in
  33. for I in Xs do
  34.       {S insertFirst(I)}
  35.    end
  36. {Check}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement