Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. attr a1
  2. meth init a1 := nil end
  3. meth isEmpty($)
  4. if @a1 == nil then true
  5. else
  6. false
  7. end
  8. end
  9. meth first($)
  10. case @a1 of nil then nil
  11. [] H|T then H
  12. else
  13. nil
  14. end
  15. end
  16. meth last($)
  17. local Last in
  18. fun {Last L}
  19. case L of H|nil then H
  20. []H|T then {Last T}
  21. else
  22. L
  23. end
  24. end
  25. {Last @a1}
  26. end
  27. end
  28. meth insertFirst(X)
  29. a1 := X|@a1
  30. end
  31. meth insertLast(X)
  32. a1 := {Append @a1 [X]}
  33. end
  34. meth removeFirst
  35. a1 := @a1.2
  36. end
  37. meth removeLast
  38. local Last in
  39. fun {Last L}
  40. case L of H|nil then nil
  41. []H|T then H|{Last T}
  42. else
  43. nil
  44. end
  45. end
  46. a1 := {Last @a1}
  47. end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement