Created
January 26, 2016 20:18
-
-
Save mhshams/3d74dd27e7a5dea16468 to your computer and use it in GitHub Desktop.
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
package io.dahgan | |
/** | |
* Stack is a data structure that stores some elements and these elements can be received in LIFO order. | |
* That means the last element that is pushed to stack would be the first one that can be poped. | |
* | |
* Our stack has a limited capacity and can not store element more than its capacity. | |
* | |
* Note to developer: | |
* - define an array of integers to keep the stack elements. | |
* - you can initialize the array with (0) in the beginning | |
* - define a variable "top" to keep the index of last element that has been added to stack. ( -1 in the beginning ) | |
*/ | |
class MyStack(capacity: Int) { | |
/** | |
* Adds the given number to the stack | |
* @return true if the push was successful, false if the stack was full | |
*/ | |
fun push(n: Int): Boolean = false | |
/** | |
* Removes the last element in the stack and returns it. | |
* @return the last element in the stack, -1 if the stack is empty | |
*/ | |
fun pop(): Int = -1 | |
/** | |
* Returns the last element in the stack WITHOUT removing it. | |
* @return the last element in the stack, -1 if the stack is empty | |
*/ | |
fun peek(): Int = -1 | |
/** | |
* Checks if the stack is empty. | |
* @return true if the stack is empty, false otherwise | |
*/ | |
fun isEmpty(): Boolean = false | |
/** | |
* Checks if the stack capacity is full. | |
* @return true if the stack is full, false otherwise | |
*/ | |
fun isFull(): Boolean = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment