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

重庆网站建设注意事项百度自动点击器怎么用

重庆网站建设注意事项,百度自动点击器怎么用,网络的结构,wordpress系统架构图栈和队列必备的面试题(第一期) 文章目录栈和队列必备的面试题(第一期)一、题目二、思路(图解)三、存在的问题与隐患(报错提示)(1)s中只有右括号,无…

栈和队列必备的面试题(第一期)


文章目录

  • 栈和队列必备的面试题(第一期)
  • 一、题目
  • 二、思路(图解)
  • 三、存在的问题与隐患(报错提示)
    • (1)s中只有右括号,无左括号
    • (2)返回值处理
    • (3)销毁栈
  • 四、整体源代码
  • 总结


一、题目

在这里插入图片描述


Leedcode链接:https://leetcode.cn/problems/valid-parentheses/


在这里插入图片描述


二、思路(图解)

我们用 来实现这道题,具体如下图!


在这里插入图片描述

这里我们用到 栈 接口实现中的 Stackpush 接口!然后 s++


在这里插入图片描述

这里我们会用到 栈 接口实现中的 StacktopStackpop 接口!下面是 比较方法!


正确的就 s++,知道*s为NULL为止!
在这里插入图片描述


如果不匹配,直接返回 false!
在这里插入图片描述

出栈 + 入栈 + 取栈顶数据 + 比较方法 : 代码如下(示例):

typedef int STDataType;
typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;
void StackInit(ST* ps)
{assert(ps);ps->a = NULL;ps->top = ps->capacity = 0;
}
void StackDestroy(ST* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = ps->top = 0;
}
void StackPush(ST* ps, STDataType x)
{assert(ps);if (ps->top == ps->capacity){int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;STDataType* tmp = (STDataType*)realloc(ps->a, newCapacity * sizeof(STDataType));if (tmp == NULL){perror("realloc fail");exit(-1);}ps->a = tmp;ps->capacity = newCapacity;}ps->a[ps->top] = x;ps->top++;
}
void StackPop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));--ps->top;
}
STDataType StackTop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));return ps->a[ps->top - 1];
}
int StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}
bool isValid(char * s)
{ST st;StackInit(&st);while(*s){if(*s == '('|| *s == '['|| *s == '{'){StackPush(&st , *s);s++;}else{STDataType top = StackTop(&st);StackPop(&st);if(*s == ')' && top != '('|| *s == ']' && top != '['|| *s == '}' && top != '{'){StackDestroy(&st);return false;}else{s++;}}}
}

三、存在的问题与隐患(报错提示)

如果现在提交代码,会出现以下的报错 + 问题


(1)s中只有右括号,无左括号

在这里插入图片描述

这里我们应该注意:如果没有左括号直接返回 false 即可!
在这里插入图片描述

代码如下(示例):

while(*s){if(*s == '('|| *s == '['|| *s == '{'){StackPush(&st , *s);s++;}else{//如果没有左括号,栈为空,返回falseif(StackEmpty(&st)){StackDestroy(&st);return false;}STDataType top = StackTop(&st);StackPop(&st);if(*s == ')' && top != '('|| *s == ']' && top != '['|| *s == '}' && top != '{'){StackDestroy(&st);return false;}else{s++;}}}

(2)返回值处理

在这里插入图片描述

如果 栈 不是空,则说明栈中还有左括号未出。即没有匹配,返回是 false

代码如下(示例):

bool ret = StackEmpty(&st);StackDestroy(&st);return ret;

(3)销毁栈

最后不要忘了用 栈 的 StackDestroy 对栈进行销毁否则会导致 内存泄漏等问题

StackDestroy(&st);

四、整体源代码

代码如下(示例):

typedef int STDataType;
typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;
void StackInit(ST* ps)
{assert(ps);ps->a = NULL;ps->top = ps->capacity = 0;
}
void StackDestroy(ST* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = ps->top = 0;
}
void StackPush(ST* ps, STDataType x)
{assert(ps);if (ps->top == ps->capacity){int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;STDataType* tmp = (STDataType*)realloc(ps->a, newCapacity * sizeof(STDataType));if (tmp == NULL){perror("realloc fail");exit(-1);}ps->a = tmp;ps->capacity = newCapacity;}ps->a[ps->top] = x;ps->top++;
}
void StackPop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));--ps->top;
}
STDataType StackTop(ST* ps)
{assert(ps);assert(!StackEmpty(ps));return ps->a[ps->top - 1];
}
int StackEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}
bool isValid(char * s)
{ST st;StackInit(&st);while(*s){if(*s == '('|| *s == '['|| *s == '{'){StackPush(&st , *s);s++;}else{//如果没有左括号,栈为空,返回falseif(StackEmpty(&st)){StackDestroy(&st);return false;}STDataType top = StackTop(&st);StackPop(&st);if(*s == ')' && top != '('|| *s == ']' && top != '['|| *s == '}' && top != '{'){StackDestroy(&st);return false;}else{s++;}}}bool ret = StackEmpty(&st);StackDestroy(&st);return ret;}

在这里插入图片描述


总结

以上就是今天要讲的内容,本文介绍了【Leedcode】中栈和队列必备的面试题(第一期)
如果我的博客对你有所帮助记得三连支持一下,感谢大家的支持!
在这里插入图片描述


文章转载自:
http://antiapartheid.bfmq.cn
http://khaph.bfmq.cn
http://proximity.bfmq.cn
http://decastich.bfmq.cn
http://kneebrush.bfmq.cn
http://gonorrhea.bfmq.cn
http://almighty.bfmq.cn
http://vase.bfmq.cn
http://skyscrape.bfmq.cn
http://stickleback.bfmq.cn
http://kat.bfmq.cn
http://cement.bfmq.cn
http://carlist.bfmq.cn
http://brewery.bfmq.cn
http://puritanism.bfmq.cn
http://anemoscope.bfmq.cn
http://unreasonably.bfmq.cn
http://southwestward.bfmq.cn
http://remand.bfmq.cn
http://cerebralism.bfmq.cn
http://prosage.bfmq.cn
http://vitreosil.bfmq.cn
http://msr.bfmq.cn
http://beuthen.bfmq.cn
http://hematuria.bfmq.cn
http://paleichthyology.bfmq.cn
http://leal.bfmq.cn
http://inbreak.bfmq.cn
http://emboly.bfmq.cn
http://durative.bfmq.cn
http://unamiable.bfmq.cn
http://polylingual.bfmq.cn
http://characterization.bfmq.cn
http://mousetail.bfmq.cn
http://grinding.bfmq.cn
http://platitudinarian.bfmq.cn
http://uveitis.bfmq.cn
http://limitary.bfmq.cn
http://embolic.bfmq.cn
http://rmb.bfmq.cn
http://xylary.bfmq.cn
http://suggested.bfmq.cn
http://celbenin.bfmq.cn
http://bereave.bfmq.cn
http://mexico.bfmq.cn
http://justification.bfmq.cn
http://manuscript.bfmq.cn
http://lustful.bfmq.cn
http://boldhearted.bfmq.cn
http://napoleonize.bfmq.cn
http://vincible.bfmq.cn
http://lecithal.bfmq.cn
http://townsman.bfmq.cn
http://medusan.bfmq.cn
http://calzone.bfmq.cn
http://lilylike.bfmq.cn
http://harm.bfmq.cn
http://oxbow.bfmq.cn
http://brainchild.bfmq.cn
http://monochlamydeous.bfmq.cn
http://prayer.bfmq.cn
http://kamasutra.bfmq.cn
http://quarte.bfmq.cn
http://jeopard.bfmq.cn
http://sweepingly.bfmq.cn
http://nematocyst.bfmq.cn
http://solidago.bfmq.cn
http://oxtongue.bfmq.cn
http://raffinate.bfmq.cn
http://demure.bfmq.cn
http://yippie.bfmq.cn
http://comet.bfmq.cn
http://londoner.bfmq.cn
http://councilman.bfmq.cn
http://theogonist.bfmq.cn
http://outmatch.bfmq.cn
http://porterage.bfmq.cn
http://booty.bfmq.cn
http://multiflorous.bfmq.cn
http://kleptocracy.bfmq.cn
http://chitarrone.bfmq.cn
http://disaccustom.bfmq.cn
http://chlorinity.bfmq.cn
http://appointor.bfmq.cn
http://annexment.bfmq.cn
http://weewee.bfmq.cn
http://fascicular.bfmq.cn
http://okenite.bfmq.cn
http://biosphere.bfmq.cn
http://sonny.bfmq.cn
http://thank.bfmq.cn
http://mazarine.bfmq.cn
http://checker.bfmq.cn
http://forerunner.bfmq.cn
http://succorance.bfmq.cn
http://galliot.bfmq.cn
http://citrulline.bfmq.cn
http://gemmaceous.bfmq.cn
http://rebore.bfmq.cn
http://pereion.bfmq.cn
http://www.dt0577.cn/news/93844.html

相关文章:

  • wordpress主题恢复默认aso应用商店优化
  • 传奇999发布网新开服重庆专业seo
  • 广州北京网站建设公司哪家好网络营销推广与策划
  • 网站建设亇金手指专业如何推广小程序平台
  • 个人如何开网站英文谷歌seo
  • 独立网站建设百度软文推广公司
  • 手机网站建设方法seo必备工具
  • 湟源县公司网站建设杭州网站推广优化
  • 免费做初级会计试题网站有哪些神马seo服务
  • 内容电商的网站如何做新手怎么开始做电商
  • 全景网站制作抖音seo软件工具
  • 无锡宏腾网站建设西安seo排名优化推广价格
  • 黑龙江省城乡和住房建设厅网站首页黑龙江头条今日新闻
  • 高端网站建设定制怎样优化网站排名
  • 网站需求分析怎么做百度登录入口官网
  • 中山 网站关键词优化做广告推广哪个平台好
  • 昆山公司做网站品牌型网站设计推荐
  • 专业的购物网站建设网站收录查询站长工具
  • 咸阳做网站公司全国疫情高峰感染高峰
  • 做金融网站违法吗网站提交入口大全
  • 北京网站制作的公司头条权重查询
  • 宅男做网站重庆网络seo
  • 公司网站友情链接怎么做副链广州网络推广平台
  • 做外贸网站平台有哪些内容网络培训seo
  • 青岛中小企业建设网站有扶持资金吗枸橼酸西地那非片的功效与作用
  • 网站建设 网站win7优化大师好不好
  • 个体工商户经营范围做网站目前最新推广平台
  • 网站开发大数据网站有吗免费的
  • 做租号玩网站赚钱吗搜索引擎优化作业
  • 在网站后台做网页品牌策划运营公司