Created
January 29, 2016 12:03
-
-
Save mhshams/67fe122f87769244c264 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 | |
/** | |
* Queue is a data structure that stores some elements and these elements can be received in FIFO order. | |
* That means the first element that is inserted to queue would be the first one that can be removed. | |
* | |
* Our queue has a limited capacity and can NOT store element more than its capacity. | |
* | |
* Note to developer: | |
* - define an array of integers to keep the queue elements. | |
* - you can initialize the array with (0) in the beginning | |
* - define a variable "head" to keep the index of first element that has been inserted to queue | |
* - define a variable "tail" to shows that index of free position to insert the new element. | |
*/ | |
class MyQueue(capacity: Int) { | |
/** | |
* Inserts the given number to the queue | |
* @return true if the insert was successful, false if the queue was full | |
*/ | |
fun insert(n: Int): Boolean = false | |
/** | |
* Removes the first element in the queue and returns it. | |
* @return the first element in the queue, -1 if the queue is empty | |
*/ | |
fun remove(): Int = -1 | |
/** | |
* Returns the first element in the queue WITHOUT removing it. | |
* @return the first element in the queue, -1 if the queue is empty | |
*/ | |
fun peek(): Int = -1 | |
/** | |
* Checks if the queue is empty. | |
* @return true if the queue is empty, false otherwise | |
*/ | |
fun isEmpty(): Boolean = false | |
/** | |
* Checks if the queue capacity is full. | |
* @return true if the queue 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