UNPKG

emath

Version:
227 lines (208 loc) 5.02 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Source: dataStruct.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: dataStruct.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * @method * @file dataStruct.js * @desc For create some data structure. * @createDate 2018.7.11. * @author yhzheng */ "use strict"; /** * @class stack * @classdesc Data structure: stack * @desc Init stack */ class stack { constructor(){ this.value = []; } /** * @method * @returns number The top value of stack * @desc To get the top value of stack */ top(){ return this.value[this.value.length - 1]; } /** * @methodk * @desc To remove the last value of stack */ pop(){ this.value.splice(this.value.length - 1,1); } /** * @method * @param {anyType} value The value of you want to pushed the value * @desc To push value */ push(value){ this.value.push(value); } /** * @method * @returns bool The stack is not empty * @desc To get the stack is not empty(true or false) */ empty(){ return this.value.length === 0; } } /** * @class queue * @classdesc Data structure: queue * @desc Init queue */ class queue { constructor(){ this.value = []; } /** * @method * @returns number The front value of queue * @desc To get the top value of queue */ front(){ return this.value[0]; } /** * @method * @returns number The back value of queue * @desc To get the back value of queue */ back(){ return this.value[this.value.length - 1]; } /** * @methodk * @desc To remove the last value of queue */ pop(){ this.value.splice(this.value.length - 1,1); } /** * @method * @param {anyType} value The value of you want to pushed the value * @desc To push value */ push(value){ this.value.push(value); } /** * @method * @returns bool The queue is not empty * @desc To get the queue is not empty(true or false) */ empty(){ return this.value.length === 0; } } /** * @class priority_queue * @classdesc Data structure: priority_queue * @desc Init priority_queue */ class priority_queue { constructor(){ this.value = []; } /** * @method * @returns number The front value of queue * @desc To get the max value of queue */ top(){ return this.value[getMax()]; } /** * @method * @returns number The front value of queue * @desc To get the top value of queue */ front(){ return this.value[0]; } /** * @method * @returns number The back value of queue * @desc To get the back value of queue */ back(){ return this.value[this.value.length - 1]; } /** * @method * @returns number The index of back value of queue * @desc To get the index of back value of queue */ getMax(){ var index = 0,max = this.value[0]; for (var i = 1 ; i &lt; this.value.length ; i++){ if (max &lt; this.value[i]){ max = this.value[i]; index = i; } } return index; } /** * @methodk * @desc To remove the last value of queue */ pop(){ this.value.splice(this.getMax(),1); } /** * @method * @param {anyType} value The value of you want to pushed the value * @desc To push value */ push(value){ this.value.push(value); } /** * @method * @returns bool The queue is not empty * @desc To get the queue is not empty(true or false) */ empty(){ return this.value.length === 0; } } module.exports.stack = stack; module.exports.queue = queue; module.exports.priority_queue = priority_queue;</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="priority_queue.html">priority_queue</a></li><li><a href="queue.html">queue</a></li><li><a href="stack.html">stack</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Mon Aug 13 2018 15:55:25 GMT+0800 (CST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>