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

广州网站建设公司怎么挑选网站被别的域名绑定

广州网站建设公司怎么挑选,网站被别的域名绑定,付网站开发费计入什么科目,wordpress查版本目录 栈的实现 1、数组栈 2、链式栈 栈的创建 栈的打印 内存泄漏 栈溢出 练习 有效的括号 栈的实现 栈后入先出 1、数组栈 (最佳实现,且访问数据的时候CPU告诉访存命中率比较高,因为地址连续存放,访问时CPU从cache里一…

目录

栈的实现

1、数组栈

2、链式栈

栈的创建

栈的打印

内存泄漏

栈溢出

练习

有效的括号


栈的实现

栈后入先出

1、数组栈

最佳实现,且访问数据的时候CPU告诉访存命中率比较高,因为地址连续存放,访问时CPU从cache里一次访问一片)

数组适合尾插尾删,所以栈底在数组头部

以下实现的就是数组栈

2、链式栈

双向链表,栈底可以是尾也可以是头

单链表,头插头删方便,所以栈顶在链表尾部

(单链表的头插头删方便在:

        头插:加减新节点只需要修改头指针指向新的节点,时间复杂度通常是O(1)

        尾插:需要遍历整个链表才能找到最后一个节点并将其之后的位置设置为新节点或者释放结点,时间复杂度是O(n)

栈的创建

栈的打印

以下是单链表的打印

此为栈的打印

栈访问一遍就已经空了

内存泄漏

后端开发,比如游戏上线了之后除了升级就不能退出,所以如果存在内存泄漏就会导致游戏越来越慢,因为可用内存资源越来越少

如果是在前端操作系统里出现了内存泄漏的情况,在进程结束掉之后就会主动释放空间,所以危害性不大

栈溢出

指的是给这个栈划分的内存区域爆了,比如写了一个死循环的递归

Stack.h

#pragma once
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>typedef int STDataType;typedef struct Stack {int* a;int top;//标识栈顶位置int capacity;//容量
}ST;void STInit(ST* pst);
void STDestroy(ST* pst);
void STPush(ST* pst, STDataType x);
void STPop(ST* pst);STDataType STTop(ST* pst);
bool STEmpty(ST* pst);
int STSize(ST* pst);

Stack.c

#define  _CRT_SECURE_NO_WARNINGS
#include"Stack.h"
void STInit(ST* pst) {assert(pst);pst->a = NULL;pst->capacity = 0;pst->top = 0;
}
void STDestroy(ST* pst) {assert(pst);free(pst->a);pst->a = NULL;pst->capacity = 0;pst->top = 0;
}
void STPush(ST* pst, STDataType x) {assert(pst);if (pst->top == pst->capacity) {int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;STDataType* tmp = (STDataType*)realloc(pst->a, sizeof(STDataType) * newcapacity);if (tmp == NULL) {perror("relloc");return;}pst->a = tmp;pst->capacity = newcapacity;}pst->a[pst->top] = x;//在a[0]的时候放入第一个值pst->top++;
}
void STPop(ST* pst) {assert(pst);assert(pst->top > 0);//不为空pst->top--;
}STDataType 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;//等于0返回真,不等于0返回假
}
int STSize(ST* pst) {assert(pst);return pst->top;
}

Test.c

#define  _CRT_SECURE_NO_WARNINGS
#include"Stack.h"void Test() {ST s;STInit(&s);STPush(&s, 1);STPush(&s, 2);STPush(&s, 3);STPush(&s, 4);while (!STEmpty(&s)) {printf("%d ", STTop(&s));//打印栈顶位置的数据STPop(&s);//弹栈}printf("\n");
}int main() {Test();return 0;
}

练习

有效的括号

数量和顺序都要匹配

#pragma once
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>typedef char STDataType;typedef struct Stack {STDataType* a;int top;//标识栈顶位置int capacity;//容量
}ST;void STInit(ST* pst);
void STDestroy(ST* pst);
void STPush(ST* pst, STDataType x);
void STPop(ST* pst);STDataType STTop(ST* pst);
bool STEmpty(ST* pst);
int STSize(ST* pst);void STInit(ST* pst) {assert(pst);pst->a = NULL;pst->capacity = 0;pst->top = 0;
}
void STDestroy(ST* pst) {assert(pst);free(pst->a);pst->a = NULL;pst->capacity = 0;pst->top = 0;
}
void STPush(ST* pst, STDataType x) {assert(pst);if (pst->top == pst->capacity) {int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;STDataType* tmp = (STDataType*)realloc(pst->a, sizeof(STDataType) * newcapacity);if (tmp == NULL) {perror("relloc");return;}pst->a = tmp;pst->capacity = newcapacity;}pst->a[pst->top] = x;//在a[0]的时候放入第一个值pst->top++;
}
void STPop(ST* pst) {assert(pst);assert(pst->top > 0);//不为空pst->top--;
}STDataType 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;//等于0返回真,不等于0返回假
}
int STSize(ST* pst) {assert(pst);return pst->top;
}bool isValid(char* s) {ST st;STInit(&st);while(*s){if(*s == '{' || *s == '[' || *s == '('){//*s是左括号就入栈STPush(&st, *s);}else{//右比左多,会导致循环时栈为空,还要弹栈if(STEmpty(&st)){//防止内存泄漏STDestroy(&st);return false;}//*s是右括号就与栈顶匹配char top = STTop(&st);STPop(&st);//检查顺序匹配if((*s == '}' && top != '{')||(*s == ']' && top != '[')||(*s == ')' && top != '(')){STDestroy(&st);return false;}}++s;}//检查数量匹配//左多右少bool ret = STEmpty(&st);//等于0就返回真,不等于0就返回假STDestroy(&st);return ret;
}

http://www.yayakq.cn/news/898395/

相关文章:

  • 网站设计论文答辩问题及答案新开传奇网站单职业
  • 广州建网站技术新乡市网站建设有哪些公司
  • 怎么建设课程的网站网络宣传渠道
  • 做网站编辑的感受外国服务器ip地址
  • 做树状图的网站电商网站建设设计报告总结
  • 网站建设方案博客海南网页设计培训
  • 做网站新乡泉州网红打卡景点
  • 网站建设的一般流程是什么意思企业网站开发制作合同
  • 广州小型网站建设公司网站建设通报
  • 自己做的网站如何让别人看到龙岩网站推广营销
  • 做图形的网站上市软件公司100强
  • 网站建设公司排行wordpress设置密码
  • 自己如何做企业网站网站服务器怎么选择
  • 建设校园门户网站理由网站设计模板
  • 游戏网站建设教程深圳市易捷网络科技有限公司
  • wap网站技术wordpress恢复备份
  • 做网站的是干嘛的黄山旅游最佳时间
  • 东莞高端网站建设费wordpress分类目录下文章过多_添加文章目录导航
  • 论文中网站数据如何做脚注做网站公司汉狮
  • 买卖平台有哪些网站跨境电子商务网页制作与网站建设
  • 齐齐哈尔住房和城乡建设局网站普通网站一年要多少钱
  • 天助网站代做土木工程专业毕业设计网站
  • 如何能让网站尽快备案通过wordpress网校
  • 汝南专业网站建设潍坊网络推广电话
  • 建设考试的报名网站网站问责建设书
  • 做国外lead应该做什么网站wordpress编辑文章出现错误500
  • 网站推广双鼎wordpress 文章主题
  • 移动网站开发百科wordpress 微信绑定域名
  • 德化网站建设萧云建设网站
  • app定制公司哪个好用常宁seo外包