Skip to content

Instantly share code, notes, and snippets.

@mhshams
Created January 29, 2016 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhshams/67fe122f87769244c264 to your computer and use it in GitHub Desktop.
Save mhshams/67fe122f87769244c264 to your computer and use it in GitHub Desktop.
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