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

济南手机端建站模板南昌seo排名优化

济南手机端建站模板,南昌seo排名优化,全国做暧小视频网站,邯郸移动网站建设报价目录 题外话 顺序表和链表优缺点以及特点 一.栈的特点 二. 栈的操作 2.1初始化 2.2 栈的销毁 2.3 栈的插入 2.3 输出top 2.4 栈的删除 2.5 输出栈 题外话 顺序表和链表优缺点以及特点 特点:顺序表,逻辑地址物理地址。可以任意访问&#xff0c…

目录

题外话

顺序表和链表优缺点以及特点

一.栈的特点

二. 栈的操作

2.1初始化 

2.2 栈的销毁

2.3 栈的插入

2.3 输出top

2.4 栈的删除

2.5 输出栈


题外话

顺序表和链表优缺点以及特点

特点:顺序表,逻辑地址=物理地址。可以任意访问,访问时间复杂度O(1).。实现分配空                         间,当空间不足时,要动态扩容。顺序表在销毁时可以直接free,但链表要一                         个个删 除。

           链表:不连续的空间靠指针指向下一个地址。不用实现分配空间。

优缺点:

            顺序表:适和访问,不适合插入删除,时间负责度为O(N)。链表适和插入删除操                           作。

一.栈的特点

        (1)先进后出

        (2)栈不能任意打印,栈只能访问栈顶

        (3)栈只能尾插头删

二. 栈的操作

2.1初始化 

         

void STInit(ST* pst) 
{assert(pst);pst->a = NULL;pst->top = -1;pst->capacity = 0;
}

2.2 栈的销毁

2.3 栈的插入

注意:🤖

如果你初始化为0,那么就是先插入在++;

如果你初始化为-1,那就是先++,在插入。

}
//插入
void STPush(ST* pst, STDataType x) 
{assert(pst);if (pst->top == pst->capacity-1){int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;STDataType* tmp = (STDataType*)realloc(pst->a, sizeof(STDataType) * newcapacity);if (tmp == NULL) {perror("realloc fail");return;}pst->a = tmp;pst->capacity = newcapacity;}pst->top++;pst->a[pst->top] = x;
}

2.3 输出top

注意:

由于栈的特性,只能先进先出,尾插头删,不能任意输出,所以我们只能输出头。

void STTop(ST* pst) 
{assert(pst);assert(pst->top >= -1);return pst->a[pst->top];
}

2.4 栈的删除

//删除
void STPop(ST* pst) 
{assert(pst);assert(pst->top>=-1);pst->top--;

2.5 输出栈

while (STEmpty(&st) != true) {printf("%d ", STTop(&st));STPop(&st);
}

 

 栈的完整代码

#pragma once
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>typedef int STDataType;
typedef struct STack
{STDataType* a;	//数值的指针是下标int top;int capacity;
}ST;void STInit(ST* pst);
void STDestory(ST* pst);
void STPush(ST* pst, STDataType x);
void STPop(ST* pst);
bool STEmpty(ST* pst);
int STSize(ST* pst);
STDataType STTop(ST* pst);#include"Stack.h"
#include<assert.h>
#include<stdio.h>
#include<stdlib.h>void STInit(ST* pst) 
{assert(pst);pst->a = NULL;pst->top = -1;pst->capacity = 0;
}
void STDestory(ST* pst) 
{assert(pst);free(pst->a);pst->a = NULL;pst->top = -1;pst->capacity = 0;}
//插入
void STPush(ST* pst, STDataType x) 
{assert(pst);if (pst->top == pst->capacity-1){int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;STDataType* tmp = (STDataType*)realloc(pst->a, sizeof(STDataType) * newcapacity);if (tmp == NULL) {perror("realloc fail");return;}pst->a = tmp;pst->capacity = newcapacity;}pst->top++;pst->a[pst->top] = x;
}
//输出头结点
STDataType STTop(ST* pst) 
{assert(pst);assert(pst->top >= -1);return pst->a[pst->top];
}
//删除
void STPop(ST* pst) 
{assert(pst);assert(pst->top>=-1);pst->top--;
}
bool STEmpty(ST* pst) 
{assert(pst);if (pst->top == -1) {return true;}else {return false;}
}
int STSize(ST* pst) 
{assert(pst);return pst->top;
}#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"Stack.h"void Test1() {ST st;STInit(&st);STPush(&st, 1);STPush(&st, 2);STPush(&st, 3);STPush(&st, 4);printf("%d\n", STTop(&st));STPop(&st);printf("%d\n", STTop(&st));while (STEmpty(&st) != true) {printf("%d ", STTop(&st));STPop(&st);}}int main() 
{Test1();return 0;
}

 

http://www.tj-hxxt.cn/news/26805.html

相关文章:

  • 可以做黄金期权的网站亚马逊关键词排名提升
  • 网站源码中国有限公司百度网盘下载的文件在哪
  • 搜索引擎营销与seo优化山东济南seo整站优化公司
  • 服务公司发展战略排名怎么优化快
  • 微信网站开发公司电话梅州网络推广
  • 装修企业网站建设推广普通话演讲稿
  • 网站开发的前端后端长沙网站关键词排名
  • 如何免费建一个网站收录排名好的发帖网站
  • 网页设置怎么设置seo服务商
  • 做时时彩网站代理费用今日头条新闻军事
  • 合肥电商网站开发人员优化方案怎么写
  • 政府网站建设工作总结360建站系统
  • 制作静态动漫网站模板线上电脑培训班
  • 南昌做兼职的网站对网络营销的认识
  • 网站建设的费用预算网站建设网络公司
  • 本溪网站建设西安seo培训
  • 做一元购网站会被封吗什么软件可以推广
  • 中石化两学一做网站刷粉网站推广免费
  • 广州地铁集团有限公司短视频优化
  • 政府门户网站 建设电商平台网站
  • 东莞气缸东莞网站建设seo搜索引擎优化策略
  • 渝北网站制作东莞百度快照优化排名
  • 宝安的医院网站建设深圳网络推广网站
  • 淘宝网站开发代发软文
  • 网站备案一般要多久全国疫情最新情况公布
  • 济南协会网站设计团队如何做线上销售和推广
  • 西安市城乡建设委员会官网站短视频培训学校
  • 禅城网站建设多少钱网站首页制作网站
  • 做公司网站的推广工作怎样上海培训机构有哪些
  • 镇海建设银行网站长春建站服务