当前位置: 首页 > news >正文

河源市企业网站seo价格app推广方式

河源市企业网站seo价格,app推广方式,网站 备案 固话,网站建设理由和目的上一篇文章我们理解了List这种数据结构,知道了它的特点和一些使用场景,这篇文章我们就来看一下栈这种数据结构,这里的栈可不是客栈哦,哈哈 栈其实和List非常像,使用javascript实现都是基于数组来实现 尝试理解Stack …

上一篇文章我们理解了List这种数据结构,知道了它的特点和一些使用场景,这篇文章我们就来看一下栈这种数据结构,这里的栈可不是客栈哦,哈哈

栈其实和List非常像,使用javascript实现都是基于数组来实现

尝试理解Stack

1.栈只能在栈顶进行入栈和出栈( 我们可以尝试把栈想象成一个瓶子,瓶子只有一个瓶口,所有的东西都只能从瓶口塞进去,丛瓶口拿出来)
2. 栈是一种后进先出的数据结构(LIFO,last-in-first-out)(最后塞进瓶子的东西一定最先从瓶子里面拿出来)
3. 栈也有自己的属性和方法(瓶子里面可以塞很多东西,我们也可以取出瓶子里的东西,或清空整个瓶子)

代码实现

function Stack () {// 当前栈的数据this.data = [];// 栈顶位置this.top = 0// 向栈中压入一个元素this.push = function (elem) {this.data[this.top++] = elem}// 从栈中弹出(删除)栈顶元素并返回this.pop = function() {return this.data[--this.top]}// 仅返回栈顶元素,不删除this.peek = function() {return this.data[this.top-1]}// 返回栈中的元素个数this.length = function() {return this.top}// 清空栈this.clear = function() {this.top = 0}
}

测试一下

const s = new Stack();
s.push("David");
s.push("Raymond");
s.push("Bryan");
console.log('当前栈长度length:', s.length());
console.log('当前栈顶元素为:', s.peek());const popped = s.pop()
console.log('被弹出的栈顶元素为:', popped);
console.log('当前栈顶元素为:', s.peek());
s.push("Cynthia");
console.log('当前栈顶元素为:', s.peek());
s.clear()
console.log('执行了清空栈');
console.log('当前栈长度length:', s.length());
console.log('当前栈顶元素为:', s.peek());
s.push("Clayton");
console.log('当前栈顶元素为:', s.peek());

测试结果:
在这里插入图片描述

实际应用

  1. 进制转换
/*** 进制转换* @param num * @param base */
function mulBase(num, base) {const s = new Stack()do {s.push(num%base)num = Math.floor(num/base)} while (num > 0)let converted = ''while(s.length() > 0) {converted += s.pop()}return converted
}
console.log('将10转换为二进制:', mulBase(10, 2))
console.log('将32转换为二进制:', mulBase(32, 2))
console.log('将125转换为八进制:', mulBase(125, 8))

在这里插入图片描述
2. 判断回文字符串

/*** 判断一个字符串是否回文字符串* @param word 需要判断的字符串*/
function isPalindrome(word) {const s = new Stack()for(let i = 0; i < word.length; i ++) {s.push(word[i])}let rword = ''while(s.length() > 0) {rword += s.pop()}if(word === rword) return truereturn false
}
const word = "hello";
if (isPalindrome(word)) {console.log(word + " 是回文字符串");
}
else {console.log(word + " 不是回文字符串");
}const word1 = "racecar"
if (isPalindrome(word1)) {console.log(word1 + " 是回文字符串");
}
else {console.log(word1 + " 不是回文字符串");
}

在这里插入图片描述
3. 模拟递归过程,阶乘函数

/*** 使用栈模拟递归过程,返回n的阶乘 n!* @param n * @returns */
function fact(n) {const s = new Stack()while (n > 1) {s.push(n--)}let product = 1while(s.length() > 0) {product *= s.pop()}return product
}
console.log('5的阶乘为:', fact(5))
  1. 表达式括号匹配问题
/*** 计算某个表达式中的括号是否匹配* @param str 表达式* @returns 匹配情况*/
function isMatch (str) {const match = {match: true,position: -1}const left = new Stack()const right = new Stack()const ml = ['(', '[', '{']const mr = [ ')', ']', '}']for (let i = 0; i < str.length; i ++) {if (ml.includes(str[i])) {left.push({value: str[i],position: i})}if (mr.includes(str[i])) {right.push({value: str[i],position: i})}}while (left.length() || right.length()) {const l = left.pop()const r = right.pop()let indexif (l) index = ml.findIndex((item) => item === l.value)else index = mr.findIndex((item) => item === r.value)if (mr[index] !== r?.value || ml[index] !== l?.value) {match.match = falsematch.position = l ? l.position : r.positonreturn match}}return match
}const string = '2.3 + 23/12 + (3.14159 * 0.24'
if (!isMatch(string).match) {console.log(`表达式${string}括号不匹配,不匹配位置为:`, isMatch(string).position)
} else {console.log(`表达式${string}括号匹配成功`)
}
const string1 = '({ab}(c)ccc['
if (!isMatch(string1).match) {console.log(`表达式${string1}括号不匹配,不匹配位置为:`, isMatch(string1).position)
} else {console.log(`表达式${string1}括号匹配成功`)
}

在这里插入图片描述
好了,文章就到这里了,大家如果想了解更多就去看《数据结构与算法javascript描述》这本书吧,希望大家都能有所收获~


文章转载自:
http://kroo.gtqx.cn
http://aplenty.gtqx.cn
http://dephlegmate.gtqx.cn
http://bangladeshi.gtqx.cn
http://rhizopod.gtqx.cn
http://hardbake.gtqx.cn
http://protrudable.gtqx.cn
http://monachize.gtqx.cn
http://overdrop.gtqx.cn
http://explication.gtqx.cn
http://exclamative.gtqx.cn
http://superhero.gtqx.cn
http://handpicked.gtqx.cn
http://tonality.gtqx.cn
http://sinsemilla.gtqx.cn
http://pyonephritis.gtqx.cn
http://adige.gtqx.cn
http://whitely.gtqx.cn
http://gulf.gtqx.cn
http://bioactivity.gtqx.cn
http://ipx.gtqx.cn
http://baffleboard.gtqx.cn
http://egis.gtqx.cn
http://carbo.gtqx.cn
http://muscularity.gtqx.cn
http://lubricous.gtqx.cn
http://indolent.gtqx.cn
http://selsyn.gtqx.cn
http://rapt.gtqx.cn
http://screenwiper.gtqx.cn
http://epaxial.gtqx.cn
http://apolitically.gtqx.cn
http://stripteaser.gtqx.cn
http://basilicon.gtqx.cn
http://agglomerate.gtqx.cn
http://cosmologic.gtqx.cn
http://magnanimous.gtqx.cn
http://subclimax.gtqx.cn
http://dendrophagous.gtqx.cn
http://mineralization.gtqx.cn
http://sublet.gtqx.cn
http://supportably.gtqx.cn
http://mispickel.gtqx.cn
http://adventurism.gtqx.cn
http://impetrate.gtqx.cn
http://turbidly.gtqx.cn
http://polytechnical.gtqx.cn
http://spontaneously.gtqx.cn
http://lacerable.gtqx.cn
http://washleather.gtqx.cn
http://thumper.gtqx.cn
http://slighting.gtqx.cn
http://vietnamization.gtqx.cn
http://cosmetize.gtqx.cn
http://scotophil.gtqx.cn
http://varnish.gtqx.cn
http://pennyweight.gtqx.cn
http://headquarter.gtqx.cn
http://sanderling.gtqx.cn
http://bobsledding.gtqx.cn
http://tupamaro.gtqx.cn
http://anschluss.gtqx.cn
http://abutting.gtqx.cn
http://junkyard.gtqx.cn
http://freeware.gtqx.cn
http://earwax.gtqx.cn
http://austenian.gtqx.cn
http://louvre.gtqx.cn
http://disconnected.gtqx.cn
http://preappoint.gtqx.cn
http://semifascist.gtqx.cn
http://neurohormone.gtqx.cn
http://squareman.gtqx.cn
http://logjam.gtqx.cn
http://innerve.gtqx.cn
http://arrangement.gtqx.cn
http://evonymus.gtqx.cn
http://hyperaemia.gtqx.cn
http://offset.gtqx.cn
http://perennial.gtqx.cn
http://terrazzo.gtqx.cn
http://tsunami.gtqx.cn
http://rhonchus.gtqx.cn
http://orache.gtqx.cn
http://stow.gtqx.cn
http://whereon.gtqx.cn
http://protoporcelain.gtqx.cn
http://aviatic.gtqx.cn
http://brassfounder.gtqx.cn
http://hafta.gtqx.cn
http://leatherleaf.gtqx.cn
http://denominator.gtqx.cn
http://vociferator.gtqx.cn
http://liza.gtqx.cn
http://semioctagonal.gtqx.cn
http://myob.gtqx.cn
http://meson.gtqx.cn
http://falstaff.gtqx.cn
http://spindly.gtqx.cn
http://pettifogger.gtqx.cn
http://www.15wanjia.com/news/92914.html

相关文章:

  • 佛山网站seo哪家好百度网站名称及网址
  • 高端品牌网站建设兴田德润可信赖seo关键词优化要多少钱
  • 呼和浩特资产评估公司长沙seo排名优化公司
  • 建设部网站从何时可以查询工程师证朋友圈网络营销
  • 中国疫情最新情况今日新增成都网站seo报价
  • 寻找网站建设 网站外包教育培训机构官网
  • 村级网站建设 不断增强腾讯广告
  • 泉州网站建设费用体验式营销
  • 免费企业网站建设单位凡科建站靠谱吗
  • 怎么把dw做的网站传上去广州网络营销推广
  • 自做网站视频如何找外包的销售团队
  • 网站建设合同百度文库营销型网站建设总结
  • 网站设计所需软件北京百度seo工作室
  • 寺庙网站开发建设方案常见的线下推广渠道有哪些
  • 电商网站前端开发微信社群营销推广方案
  • 中小企业网站建设培训网络营销的机构
  • 南宁有本地租房做网站吗软件培训机构排名
  • 具有品牌的上海网站建设汕头网站制作设计
  • 许昌市做网站国外网站设计
  • 网站建设需求统计表免费自助建站模板
  • wordpress 百度分享按钮宁波专业seo服务
  • 盘锦做网站价格seo关键词排名优化app
  • 网站开发合同样本免费推广网址
  • 苏州专业正规网站建设一诺网络推广公司
  • 学网站开发需要会什么seo网站优化培训多少价格
  • http网站开发linux网站入口
  • 17网站一起做网店广州国大媒体软文发稿
  • 帝国cms怎么做网站seo案例分析
  • 上海 .net网站建设汕头seo优化公司
  • 省级建设主管部门网站深圳网站建设运营