Stack is an abstract data type that serves as a collection of elements according to the principle LIFO – "last in, first out". We want you to create your own stack class named MyStack based on the List, which stores values of some type. Implement the methods push() to add items to the top of the stack and pop() to remove the top element and return its value.
Introduction to generic programming
Stack Kotlin Flow
Report a typo
Write a program in Kotlin
class MyStack<T>(data: List<T>) {
val items = data.toMutableList()
// implement methods
fun push(data: T) {}
fun pop(): T {}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.