Guest User

Untitled

a guest
Dec 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class Stack {
  2. List items;
  3. Stack(this.items);
  4. @override
  5. String toString() => 'List :$items';
  6.  
  7. void push(int item) {
  8. this.items.add(item);
  9. }
  10.  
  11. int pull() {
  12. return this.items.removeLast();
  13. }
  14.  
  15. bool is_empty() {
  16. if (this.items == []) {
  17. return true;
  18. } else {
  19. return false;
  20. }
  21. }
  22. }
  23.  
  24. main() {
  25. var s = Stack([10, 9]);
  26. s.push(1);
  27. s.push(2);
  28. s.push(3);
  29. print(s);
  30. print("---------");
  31.  
  32. while (!s.is_empty()) {
  33. int item = s.pull();
  34. print(item);
  35. }
  36. }
Add Comment
Please, Sign In to add comment