Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. empty_stack([]).
  2. push(Q, X, [X|Q]).
  3. top([H|T], H).
  4. pop([H|T], T).
  5.  
  6. progr:-
  7. empty_stack(L),
  8. read_stack(L,0).
  9.  
  10. read_stack(L,5):-
  11. print_stack(L, 0).
  12.  
  13. print_stack(L,5):-
  14. write("telos").
  15.  
  16. read_stack(L,Cnt):-
  17. write("dose stoixeio "),
  18. read(El),
  19. push(L, El, NewL),
  20. NCnt is Cnt+1,
  21. read_stack(NewL,NCnt).
  22.  
  23. print_stack(L, Cnt):-
  24. top(L, TopEl),
  25. nl,
  26. write(TopEl),
  27.  
  28. pop(L,NewL),
  29. NCnt is Cnt+1,
  30. print_stack(NewL, NCnt).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement