Data Structure
- Stack
Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). This strategy states that the element that is inserted last will come out first.
Get Arya P’s stories in your inbox
Join Medium for free to get updates from this writer.
Operations in Stack
- Push(): Insert an element into the stack.
- Pop() : Remove an element from the stack.
Source Code
void main() {
final myStack = Stack<String>();myStack.push(‘A’);
myStack.push(‘B’);
myStack.push(“C”);
myStack.push(“D”);
myStack.push(“E”);print(myStack.toString());
var element = myStack.pop();
print(element);
}class Stack<E> {
List<String> list =[];
push(String e){
list.add(e);
}
String pop()=>list.removeLast();@override
String toString() => list.toString();
}





