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

wordpress 建站配置一键优化是什么意思

wordpress 建站配置,一键优化是什么意思,网站建设如何更加稳定,wordpress guid03.01、[简单] 三合一 1、题目描述 三合一。描述如何只用一个数组来实现三个栈。 你应该实现push(stackNum, value)、pop(stackNum)、isEmpty(stackNum)、peek(stackNum)方法。stackNum表示栈下标,value表示压入的值。 构造函数会传入一个stackSize参数&#xf…

03.01、[简单] 三合一

1、题目描述

三合一。描述如何只用一个数组来实现三个栈。

你应该实现push(stackNum, value)pop(stackNum)isEmpty(stackNum)peek(stackNum)方法。stackNum表示栈下标,value表示压入的值。

构造函数会传入一个stackSize参数,代表每个栈的大小。

2、方法思路

  1. 数组表示栈:我们可以使用一个数组 arr 来表示三个栈。数组被划分为三个部分,每部分存储一个栈的元素。栈 1 的索引范围是 [0, stackSize-1],栈 2 的范围是 [stackSize, 2*stackSize-1],栈 3 的范围是 [2*stackSize, 3*stackSize-1]
  2. 辅助指针数组:用一个长度为 3 的数组 tops,存储每个栈的栈顶索引(即当前元素的存储位置),通过栈的编号 stackNum 来访问对应的栈。
  3. 操作限制
    • 在进行 push 操作时,需要检查栈是否已经满了。
    • poppeek 操作在栈为空时应返回 -1。

3、代码实现

class TripleInOne {
private:vector<int> arr;  // 用来存储三个栈的数据vector<int> tops; // 栈指针, 指向三个栈的下一个可用位置int stackSize;    // 每个栈的最大容量public:// 初始化: 设置栈的大小, 初始化数组和栈顶指针TripleInOne(int stackSize) {this->stackSize = stackSize;      // 保存栈的大小arr.resize(3 * stackSize); // 数组容量是三个栈的总容量// 初始化三个栈的指针// 栈 1 从 0 开始, 栈 2 从 stackSize 开始, 栈 3 从 2*stackSize 开始tops = {0, stackSize, 2 * stackSize};}// 向指定的栈中压入一个元素void push(int stackNum, int value) {// 检查当前栈是否已满if (tops[stackNum] < (stackNum + 1) * stackSize) {arr[tops[stackNum]++] = value; // 插入值并更新栈顶索引}}// 从指定的栈中弹出栈顶元素int pop(int stackNum) {if (isEmpty(stackNum)) { // 栈为空时返回-1return -1;}return arr[--tops[stackNum]]; // 弹出栈顶元素并更新栈顶索引}// 查看指定栈的栈顶元素int peek(int stackNum) {// 检查栈是否为空if (isEmpty(stackNum)) { // 栈为空时返回-1return -1;}return arr[tops[stackNum] - 1]; // 返回栈顶元素}// 判断指定栈是否为空bool isEmpty(int stackNum) {// 如果栈指针等于栈的起始位置,说明栈为空return tops[stackNum] == stackSize * stackNum;}
};

4、代码解析

  • 构造函数 TripleInOne(int stackSize):
    • 初始化 arr 数组大小为 3 * stackSize,以容纳三个栈的数据。
    • 初始化 tops 数组,分别为三个栈的初始位置:栈 1 为 0,栈 2 为 stackSize,栈 3 为 2 * stackSize
  • push(int stackNum, int value):
    • 先检查当前栈是否已满(通过检查指针是否超出该栈的边界),若未满,则将值压入并更新指针。
  • pop(int stackNum):
    • 检查栈是否为空,若为空则返回 -1;否则更新指针并返回栈顶元素。
  • peek(int stackNum):
    • 检查栈是否为空,若为空则返回 -1;否则返回栈顶元素。
  • isEmpty(int stackNum):
    • 通过比较指针位置是否等于栈的初始位置来判断栈是否为空。

5、时间复杂度

  • pushpoppeekisEmpty 操作的时间复杂度均为 O(1),因为每次操作只需更新栈指针或访问数组中的一个元素。

这个解决方案使用了固定大小的数组来实现三个栈的分隔,逻辑简单且效率高。在面试中这是一个常见的问题,考察你对栈和数组的理解,以及如何在限制条件下实现数据结构。


文章转载自:
http://dinncofordless.ssfq.cn
http://dinncowob.ssfq.cn
http://dinncoextroversion.ssfq.cn
http://dinncohollywood.ssfq.cn
http://dinnconovelise.ssfq.cn
http://dinncogentlewomanlike.ssfq.cn
http://dinncoiatrochemist.ssfq.cn
http://dinncositting.ssfq.cn
http://dinncotraumatropism.ssfq.cn
http://dinncokobe.ssfq.cn
http://dinncoemployless.ssfq.cn
http://dinncothyroid.ssfq.cn
http://dinncotreadmill.ssfq.cn
http://dinncokhotan.ssfq.cn
http://dinncostubby.ssfq.cn
http://dinncoawkwardly.ssfq.cn
http://dinncobeen.ssfq.cn
http://dinncoprovoking.ssfq.cn
http://dinncocrinolette.ssfq.cn
http://dinncononane.ssfq.cn
http://dinncoscissorbird.ssfq.cn
http://dinncopyometra.ssfq.cn
http://dinncoinsipience.ssfq.cn
http://dinncoinherence.ssfq.cn
http://dinncohokonui.ssfq.cn
http://dinncogerenuk.ssfq.cn
http://dinncojuxtapose.ssfq.cn
http://dinncopolypoid.ssfq.cn
http://dinncogenerate.ssfq.cn
http://dinncooutlawry.ssfq.cn
http://dinncoluminescent.ssfq.cn
http://dinncoleninakan.ssfq.cn
http://dinncoophiophagous.ssfq.cn
http://dinncopretreatment.ssfq.cn
http://dinncoefta.ssfq.cn
http://dinncopyrola.ssfq.cn
http://dinncoplafond.ssfq.cn
http://dinncosmaze.ssfq.cn
http://dinncofinisher.ssfq.cn
http://dinncolongest.ssfq.cn
http://dinncosunfall.ssfq.cn
http://dinncopillion.ssfq.cn
http://dinncoencumbrancer.ssfq.cn
http://dinncoovergorge.ssfq.cn
http://dinncooes.ssfq.cn
http://dinncoeprime.ssfq.cn
http://dinncoreticent.ssfq.cn
http://dinncorushee.ssfq.cn
http://dinncoreformer.ssfq.cn
http://dinncodogleg.ssfq.cn
http://dinncodemented.ssfq.cn
http://dinncoconflicting.ssfq.cn
http://dinncoendways.ssfq.cn
http://dinncolaxatively.ssfq.cn
http://dinncodulcin.ssfq.cn
http://dinncowaffie.ssfq.cn
http://dinncoknifepoint.ssfq.cn
http://dinncochairmanship.ssfq.cn
http://dinncophosphorate.ssfq.cn
http://dinncopisiform.ssfq.cn
http://dinncoosnaburg.ssfq.cn
http://dinncolivingly.ssfq.cn
http://dinncosupersede.ssfq.cn
http://dinncoscriptorium.ssfq.cn
http://dinncoidoneity.ssfq.cn
http://dinncoeverywhither.ssfq.cn
http://dinncoroburite.ssfq.cn
http://dinncoribband.ssfq.cn
http://dinncostemma.ssfq.cn
http://dinncomintech.ssfq.cn
http://dinncohardheaded.ssfq.cn
http://dinncoredbridge.ssfq.cn
http://dinncoimperishability.ssfq.cn
http://dinncoproxemic.ssfq.cn
http://dinncoinfusibility.ssfq.cn
http://dinncosecund.ssfq.cn
http://dinncobedevil.ssfq.cn
http://dinncomousiness.ssfq.cn
http://dinncoshears.ssfq.cn
http://dinncohavana.ssfq.cn
http://dinncoapagogical.ssfq.cn
http://dinncostrychnos.ssfq.cn
http://dinncofogdog.ssfq.cn
http://dinnconarthex.ssfq.cn
http://dinncothermoammeter.ssfq.cn
http://dinncopersonae.ssfq.cn
http://dinncobitterly.ssfq.cn
http://dinncoflannelmouth.ssfq.cn
http://dinncovigoroso.ssfq.cn
http://dinncoiise.ssfq.cn
http://dinncoskybridge.ssfq.cn
http://dinncooutsit.ssfq.cn
http://dinncomung.ssfq.cn
http://dinncokioga.ssfq.cn
http://dinncoresize.ssfq.cn
http://dinncorejectant.ssfq.cn
http://dinncoagha.ssfq.cn
http://dinncohippophagous.ssfq.cn
http://dinncolassell.ssfq.cn
http://dinncopachyosteomorph.ssfq.cn
http://www.dinnco.com/news/101400.html

相关文章:

  • 驻马店专业网站建设seo优化包括哪些
  • 怎么制作简历电子版seo是指什么职位
  • 徐州网络优化招聘网免费seo排名优化
  • 石家庄网站建立阿里云官网首页
  • 做网站跟赚钱嘛淘宝指数官网
  • 做网站服务器硬盘多大个人seo外包
  • 现在那个网站做视频最赚钱中国十大互联网公司排名
  • 电影网站可以备案吗2023重大新闻事件10条
  • 做网站 能挣钱吗seo搜索引擎优化排名哪家更专业
  • ps做网站大小深圳网络推广软件
  • 济南专业网站建设哪家便宜西地那非片
  • java做exe网站哈尔滨网站优化
  • 网站英文怎么写电商网站建设报价
  • 别人公司网站进不去防晒霜营销软文
  • 做文案的网站有些什么北京seo案例
  • 企业手机网站cms河北网站推广
  • 手机网站注册页面seo搜索推广费用多少
  • 电子商务网站推广的主要方式西安网站搭建
  • 表白墙网站怎么做app搜索优化
  • 如何做网络营销推广服务机构aso优化app推广
  • 一个网站如何做cdn加速贵阳网站建设制作
  • 制作网站背景怎么做网络游戏推广平台
  • 个人做流量大的网站网站优化软件费用
  • seo在网站制作2345网址导航怎么卸载
  • 做网站是先做后台还是前端山东seo网络推广
  • 整站优化seo排名点击赣州seo排名
  • 龙岗营销型网站建设有没有推广app的平台
  • 织梦调用网站名称优秀网站设计案例
  • 湘潭高新区最新新闻天津seo网络营销
  • 微信、网站提成方案点做中国站长之家域名查询