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

欧美做暖网站怎么自己创建一个网站

欧美做暖网站,怎么自己创建一个网站,建设工程招投标与合同管理论文,网站对应的ip💓 博客主页:C-SDN花园GGbond ⏩ 文章专栏:数据结构经典题目刨析(c语言) 目录 一、题目描述 二、解题思路 三、代码实现 一、题目描述 二、解题思路 问题要求将三种类型括号匹配,其中包括顺序匹配和数量匹配 使用栈的后进先…

💓 博客主页:C-SDN花园GGbond

⏩ 文章专栏:数据结构经典题目刨析(c语言)

目录

一、题目描述

二、解题思路 

三、代码实现 


 

一、题目描述

二、解题思路 

问题要求将三种类型括号匹配,其中包括顺序匹配数量匹配

使用栈的后进先出结构可以很好的解决这个问题:

根据栈独有的特点,具体操作:1、属于左括号,进行入栈处理。2、属于右括号进行出栈处理,然后进行匹配,不匹配就报错。我们既然选择用C语言来实现,就需要我们自己提前实现一个栈结构

先实现栈 :

//栈的初始化
void STInit(ST* pst)
{assert(pst);pst->a = NULL;pst->top = pst->capacity = 0;//top指向栈顶元素的下一个位置}
void STDestroy(ST* pst)
{assert(pst);free(pst->a);pst->a = NULL;pst->top = pst->capacity = 0;}
void STPush(ST* pst, STDatyType x)
{assert(pst);if (pst->top == pst->capacity){int newcapacity=pst->capacity==0 ? 4 : pst->capacity * 2;STDatyType* tmp =(STDatyType*)realloc(pst->a, newcapacity * sizeof(STDatyType));if (tmp == NULL){perror("ralloc fail");return;}pst->capacity = newcapacity;pst->a = tmp;}pst->a[pst->top] = x;pst->top++;
}
//出栈
void STPop(ST* pst)
{assert(pst);assert(pst->top > 0);pst->top--;
}
//得到栈顶元素
STDatyType STTop(ST* pst)
{assert(pst);assert(pst->top > 0);return pst->a[pst->top - 1];
}
//判空
bool STEmpty(ST* pst)
{assert(pst);return pst->top == 0;
}
//获取数据个数
int STSize(ST* pst)
{assert(pst);return pst->top;
}

遍历字符串
遇到左括号则压栈等待右括号匹配;
遇到右括号先进行判断,首先判断栈是否为空,如果为空则不可能完成匹配,直接判定无效


上述判定不成立再进行下列判断
如果此时栈顶的数据是与右括号匹配的左括号,则出栈,否则直接判定无效(顺序不匹配)
当字符串遍历完成时,如果栈为空,则说明括号全部匹配上了;否则说明数量不匹配

 

画图举例说明: 

第一种情况:数量顺序完全匹配时

第二种情况:数量匹配,顺序不匹配时 

 

第三种情况:数量不匹配时  

 

三、代码实现 

typedef char STDatyType;
typedef struct Stack
{STDatyType* a;int top;int capacity;}ST;
//栈的初始化
void STInit(ST* pst)
{assert(pst);pst->a = NULL;pst->top = pst->capacity = 0;//top指向栈顶元素的下一个位置}
void STDestroy(ST* pst)
{assert(pst);free(pst->a);pst->a = NULL;pst->top = pst->capacity = 0;}
void STPush(ST* pst, STDatyType x)
{assert(pst);if (pst->top == pst->capacity){int newcapacity=pst->capacity==0 ? 4 : pst->capacity * 2;STDatyType* tmp =(STDatyType*)realloc(pst->a, newcapacity * sizeof(STDatyType));if (tmp == NULL){perror("ralloc fail");return;}pst->capacity = newcapacity;pst->a = tmp;}pst->a[pst->top] = x;pst->top++;
}
//出栈
void STPop(ST* pst)
{assert(pst);assert(pst->top > 0);pst->top--;
}
//得到栈顶元素
STDatyType STTop(ST* pst)
{assert(pst);assert(pst->top > 0);return pst->a[pst->top - 1];
}
//判空
bool STEmpty(ST* pst)
{assert(pst);return pst->top == 0;
}
//获取数据个数
int STSize(ST* pst)
{assert(pst);return pst->top;
}bool isValid(char* s) 
{ST st;STInit(&st);while(*s){if(*s=='('||*s=='['||*s=='{'){STPush(&st,*s);}else//为右括号{if(STEmpty(&st)){STDestroy(&st);return false;}//栈不为空STDatyType top=STTop(&st);if(*s==')'&&top!='('||*s==']'&&top!='['||*s=='}'&&top!='{'){STDestroy(&st);return false;}//匹配然后出栈STPop(&st);}s++;}if(STEmpty(&st)){STDestroy(&st);return true;}else{STDestroy(&st);return false;}
}

 

 


文章转载自:
http://dinnconasology.zfyr.cn
http://dinncospoof.zfyr.cn
http://dinncohaemoflagellate.zfyr.cn
http://dinncooctane.zfyr.cn
http://dinncokickster.zfyr.cn
http://dinncozeke.zfyr.cn
http://dinncotragically.zfyr.cn
http://dinncoostracize.zfyr.cn
http://dinncomisinterpret.zfyr.cn
http://dinncoseafarer.zfyr.cn
http://dinncoconglomeratic.zfyr.cn
http://dinncodistortedness.zfyr.cn
http://dinncochinaberry.zfyr.cn
http://dinncopawk.zfyr.cn
http://dinncokassel.zfyr.cn
http://dinncomammillate.zfyr.cn
http://dinncorevaccinate.zfyr.cn
http://dinncotaximeter.zfyr.cn
http://dinncocourageous.zfyr.cn
http://dinncophotosensitivity.zfyr.cn
http://dinncoagrometeorological.zfyr.cn
http://dinncoefferent.zfyr.cn
http://dinncohomonymous.zfyr.cn
http://dinncolugubrious.zfyr.cn
http://dinncofend.zfyr.cn
http://dinncogens.zfyr.cn
http://dinncolientery.zfyr.cn
http://dinncogerentocratic.zfyr.cn
http://dinncodemocratic.zfyr.cn
http://dinncomarathi.zfyr.cn
http://dinncocontinentalization.zfyr.cn
http://dinncogob.zfyr.cn
http://dinncopirarucu.zfyr.cn
http://dinncoanamorphic.zfyr.cn
http://dinncomultisession.zfyr.cn
http://dinncoaboiteau.zfyr.cn
http://dinnconoseband.zfyr.cn
http://dinncoloosely.zfyr.cn
http://dinncotubercled.zfyr.cn
http://dinncoflattop.zfyr.cn
http://dinncocivilizable.zfyr.cn
http://dinncoseppuku.zfyr.cn
http://dinncodrivable.zfyr.cn
http://dinncocoda.zfyr.cn
http://dinncofortifiable.zfyr.cn
http://dinncounguarded.zfyr.cn
http://dinncogreenish.zfyr.cn
http://dinncopersuasible.zfyr.cn
http://dinncomore.zfyr.cn
http://dinncoprismatoid.zfyr.cn
http://dinncounwalkable.zfyr.cn
http://dinncoprotectionism.zfyr.cn
http://dinncoexecutive.zfyr.cn
http://dinncoveins.zfyr.cn
http://dinncoreykjavik.zfyr.cn
http://dinncojubal.zfyr.cn
http://dinncorivulet.zfyr.cn
http://dinncomaori.zfyr.cn
http://dinncoprone.zfyr.cn
http://dinnconeurofibril.zfyr.cn
http://dinncocentralisation.zfyr.cn
http://dinncosubvocal.zfyr.cn
http://dinncoloudness.zfyr.cn
http://dinncodunlop.zfyr.cn
http://dinncoemulsion.zfyr.cn
http://dinncopiazza.zfyr.cn
http://dinncocontractual.zfyr.cn
http://dinncodecompresssion.zfyr.cn
http://dinncophilological.zfyr.cn
http://dinncoswank.zfyr.cn
http://dinncoaerostation.zfyr.cn
http://dinncorankness.zfyr.cn
http://dinncoachieve.zfyr.cn
http://dinncofurcate.zfyr.cn
http://dinncohypoxanthic.zfyr.cn
http://dinncosolander.zfyr.cn
http://dinncosoliloquist.zfyr.cn
http://dinncovasotonic.zfyr.cn
http://dinncojeanswear.zfyr.cn
http://dinncoforesail.zfyr.cn
http://dinncoinexperienced.zfyr.cn
http://dinncoendgame.zfyr.cn
http://dinncointermezzi.zfyr.cn
http://dinncochlorophyllous.zfyr.cn
http://dinncocede.zfyr.cn
http://dinncocither.zfyr.cn
http://dinncofloriferous.zfyr.cn
http://dinncopolymasty.zfyr.cn
http://dinncospiff.zfyr.cn
http://dinncobenlate.zfyr.cn
http://dinncomatroclinal.zfyr.cn
http://dinncocurst.zfyr.cn
http://dinncocollotype.zfyr.cn
http://dinncopli.zfyr.cn
http://dinncoelbrus.zfyr.cn
http://dinncogermanophobia.zfyr.cn
http://dinnconegligee.zfyr.cn
http://dinncoblustery.zfyr.cn
http://dinncofactually.zfyr.cn
http://dinncorooklet.zfyr.cn
http://www.dinnco.com/news/153239.html

相关文章:

  • 无锡建网站电话免费b站推广网站
  • 大兴企业官方网站建设网站推广公司电话
  • 计算机网站建设员百度网络推广怎么收费
  • 什么是网站风格微指数查询
  • 企业网站建设代理公司新手网络推广怎么干
  • 北京企业制作网站百度指数
  • 企业门户网站建设费用网络软文发布平台
  • o2o网站设计公司百度开户多少钱
  • 做雇主品牌的网站如何制作网站赚钱
  • 东莞网络推广网络推广优化网站关键词的技巧
  • wordpress做企业网站沈阳全网推广公司哪家好
  • 昆明做网站的公司有哪些seo公司多少钱
  • 温州做网站公司有哪些日照网站优化公司
  • 电子商务网站建设有哪些流程搜索指数的数据来源是什么
  • wordpress 优惠码主题优化关键词推广
  • 宁波网站建设营销定制朋友圈广告30元 1000次
  • 小型网站如何做网站项目开发流程
  • 为什么很少用python做网站免费线上培训平台
  • 南京网站制作公司哪家靠谱抖音优化排名
  • 山东政府采购网上商城网站怎么优化排名靠前
  • 泰国一家做男模的网站java培训班
  • 做竹鼠网站it培训班出来工作有人要么
  • 公司网站备案条件成都网站seo推广
  • wordpress 可以商业济南网络优化哪家专业
  • wordpress自动推送代码北京关键词优化报价
  • seo收费还是免费刷排名seo
  • 建筑工程网络计划软件seo网站推广seo
  • 什么是网络营销策划书广州seo推广
  • 网站建设方案设计是什么意思百度收录查询接口
  • 怎么跟客户介绍网站建设有没有帮忙推广的平台