Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %SEQUENCE
- attr x
- meth init x:=nil end
- meth isEmpty($) @x==nil end
- meth first($) @x.1 end
- meth last($) {Nth @x {Length @x}} end
- meth insertFirst(X) x:= X|@x end
- meth insertLast(X) x:={Append @x X|nil} end
- meth removeFirst x:=@x.2 end
- meth removeLast
- local L in
- L=@x
- x:=nil
- for I in {Length L}-1..1;~1 do
- x:= {Nth L I}|@x
- end
- end
- end
- %PALINDROME
- S={New Sequence init}
- fun{Check}
- if {S isEmpty($)} then true
- else
- if {S first($)}=={S last($)} then
- {S removeFirst}
- {S removeLast}
- {Check}
- else false end
- end
- end
- in
- for I in Xs do
- {S insertFirst(I)}
- end
- {Check}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement