Last active
December 12, 2018 20:47
-
-
Save SajidK25/e316f871b7edd1ad2d2a56a76be1de01 to your computer and use it in GitHub Desktop.
Simple Stack [LIFO] behaviour Implementation using Dart Programming Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stack { | |
List items; | |
Stack(this.items); | |
@override | |
String toString() => 'List :$items'; | |
void push(int item) { | |
this.items.add(item); | |
} | |
int pull() { | |
return this.items.removeLast(); | |
} | |
bool is_empty() { | |
if (this.items == []) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
main() { | |
var s = Stack([10, 9]); | |
s.push(1); | |
s.push(2); | |
s.push(3); | |
print(s); | |
print("---------"); | |
while (!s.is_empty()) { | |
int item = s.pull(); | |
print(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment