Skip to content

Instantly share code, notes, and snippets.

@SajidK25
Last active December 12, 2018 20:47
Show Gist options
  • Save SajidK25/e316f871b7edd1ad2d2a56a76be1de01 to your computer and use it in GitHub Desktop.
Save SajidK25/e316f871b7edd1ad2d2a56a76be1de01 to your computer and use it in GitHub Desktop.
Simple Stack [LIFO] behaviour Implementation using Dart Programming Language
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