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

网站如何做微信分享推广域名官网

网站如何做微信分享推广,域名官网,仿牌网站建设,泰安网络安全培训文章目录 目录1. 数据结构相关概念1.1 什么是数据结构1.2 为什么需要数据结构 2. 顺序表的概念及结构3. 顺序表分类4. 实现动态顺序表4.1 初始化4.2 顺序表的尾部插入4.3 打印顺序表4.4 顺序表的头部插入4.5 顺序表的尾部删除4.6 顺序表的头部删除4.7 指定位置之前插入数据4.8 …

文章目录

  • 目录
    • 1. 数据结构相关概念
      • 1.1 什么是数据结构
      • 1.2 为什么需要数据结构
    • 2. 顺序表的概念及结构
    • 3. 顺序表分类
    • 4. 实现动态顺序表
      • 4.1 初始化
      • 4.2 顺序表的尾部插入
      • 4.3 打印顺序表
      • 4.4 顺序表的头部插入
      • 4.5 顺序表的尾部删除
      • 4.6 顺序表的头部删除
      • 4.7 指定位置之前插入数据
      • 4.8 删除指定位置数据
      • 4.9 在顺序表中查找x
      • 4.10 顺序表的销毁

目录

  • 数据结构相关概念
  • 顺序表概念及结构
  • 顺序表分类
  • 实现动态顺序表

1. 数据结构相关概念

1.1 什么是数据结构

数据结构是由“数据”和“结构”两词组合而来。

什么是数据?

常见的数值1、2、3、4…、教务系统里保存的用户信息(姓名、性别、年龄、学历等等)、网页里肉眼可以看到的信息(文字、图片、视频等等),这些都是数据。

什么是结构?

当我们想要大量使用同⼀类型的数据时,通过手动定义大量的独立的变量对于程序来说,可读性非常差,我们可以借助数组这样的数据结构将⼤量的数据组织在⼀起,结构也可以理解为组织数据的方式。

概念: 数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在⼀种或多种特定关系的数据元素的集合。数据结构反映数据的内部构成,即数据由哪部分构成,以什么方式构成,以及数据元素之间呈现的结构。

总结:
1)能够存储数据(如顺序表、链表等结构)
2)存储的数据能够方便查找

1.2 为什么需要数据结构

程序中如果不对数据进行管理,可能会导致数据丢失、操作数据困难、野指针等情况。通过数据结构,能够有效将数据组织和管理在⼀起。按照我们的方式任意对数据进行增删改查等操作。

最基础的数据结构:数组。

【思考】有了数组,为什么还要学习其他的数据结构?

假定数组有10个空间,已经使用了5个,向数组中插入数据的步骤:

  1. 求数组的长度,求数组的有效数据个数
  2. 向下标为数据有效个数的位置插入数据(注意:这里是否要判断数组是否满了,满了还能继续插入吗)
  3. 假设数据量非常庞大,频繁的获取数组有效数据个数会影响程序执行效率。

结论: 最基础的数据结构能够提供的操作已经不能完全满足复杂算法实现。

2. 顺序表的概念及结构

线性表:

线性表(linear list)是n个具有相同特性的数据元素的有限序列。 线性表是⼀种在实际中广泛使用的数据结构,常见的线性表:顺序表、链表、栈、队列、字符串… 线性表在逻辑上是线性结构,也就说是连续的⼀条直线;但是在物理结构上并不⼀定是连续的,线性表在物理上存储时,通常以数组和链式结构的形式存储。

顺序表:

逻辑结构是线性的、物理结构是连续的。

顺序表和数组的区别:

顺序表的底层结构是数组,对数组的封装,实现了常用的增删改查等接口。

3. 顺序表分类

  1. 静态顺序表

概念:使用定长数组存储元素

//静态顺序表#define N 100typedef int SLDataType;//顺序表中数组类型不一定是整型,如果要变为字符类型,就可以在这里直接改;如果不这样定义,就要在代码中改很多次struct SeqList
{SLDataType a[N];//定长数组int size;//有效数据个数
};

静态顺序表缺陷:空间给少了不够⽤,给多了造成空间浪费

  1. 动态顺序表
//动态顺序表typedef int SLDataType;typedef struct SeqList
{SLDataType* arr;//存储数据的底层结构int capacity;//记录顺序表的空间大小int size;//记录顺序表当前有效的数据个数
}SL;//typedef struct SeqList SL;

4. 实现动态顺序表

4.1 初始化

void SLInit(SL* ps)
{assert(ps);ps->arr = NULL;ps->size = ps->capacity = 0;
}

4.2 顺序表的尾部插入

void SLCheckCapacity(SL* ps)
{if (ps->size == ps->capacity){int newCapacity = 0 == ps->capacity ? 4 : 2 * ps->capacity;SLDataType* tmp = (SLDataType*)realloc(ps->arr, newCapacity * sizeof(SLDataType));if (NULL == tmp){perror("realloc fail!");exit(1);}//扩容成功ps->arr = tmp;ps->capacity = newCapacity;}
}void SLPushBack(SL* ps, SLDataType x)
{//断言 -- 粗暴的解决方式//assert(ps != NULL);assert(ps);//if判断 -- 温柔的解决方式//if (NULL == ps)//{//	return;//}//空间不够,扩容SLCheckCapacity(ps);//空间足够,直接插入ps->arr[ps->size++] = x;//ps->size++;
}

注:
扩容的原则:成倍数的增加(1.5倍、2倍)

4.3 打印顺序表

void SLPrint(SL* ps)
{assert(ps);for (int i = 0; i < ps->size; i++){printf("%d ", ps->arr[i]);}printf("\n");
}

4.4 顺序表的头部插入

void SLPushFront(SL* ps, SLDataType x)
{assert(ps);//判断是否扩容SLCheckCapacity(ps);//旧数据往后挪动一位for (int i = ps->size; i > 0; i--){ps->arr[i] = ps->arr[i - 1];}ps->arr[0] = x;ps->size++;
}

4.5 顺序表的尾部删除

void SLPopBack(SL* ps)
{assert(ps);assert(ps->size);//顺序表不为空ps->size--;
}

4.6 顺序表的头部删除

void SLPopFront(SL* ps)
{assert(ps);assert(ps->size);//不为空执行挪动操作for (int i = 0; i < ps->size - 1; i++){ps->arr[i] = ps->arr[i + 1];}ps->size--;
}

4.7 指定位置之前插入数据

void SLInsert(SL* ps, int pos, SLDataType x)
{assert(ps);assert(pos >= 0 && pos <= ps->size);SLCheckCapacity(ps);//pos及之后的数据往后挪动一位,pos空出来for (int i = ps->size; i > pos; i--){ps->arr[i] = ps->arr[i - 1];}ps->arr[pos] = x;ps->size++;
}

4.8 删除指定位置数据

void SLErase(SL* ps, int pos)
{assert(ps);assert(pos >= 0 && pos < ps->size);//pos以后的数据往前挪动一位for (int i = pos; i < ps->size - 1; i++){ps->arr[i] = ps->arr[i + 1];}ps->size--;
}

4.9 在顺序表中查找x

int SLFind(SL* ps, SLDataType x)
{//加上断言对代码的健壮性更好assert(ps);for (int i = 0; i < ps->size; i++){if (x == ps->arr[i]){return i;}}return -1;
}

4.10 顺序表的销毁

void SLDestroy(SL* ps)
{assert(ps);free(ps->arr);ps->arr = NULL;ps->size = ps->capacity = 0;
}

完整代码:

//SeqList.h#include <stdio.h>
#include <stdlib.h>
#include <assert.h>静态顺序表
//
//#define N 100
//
//typedef int SLDataType;
//
//struct SeqList
//{
//	SLDataType a[N];
//	int size;
//};//动态顺序表typedef int SLDataType;typedef struct SeqList
{SLDataType* arr;//存储数据的底层结构int capacity;//记录顺序表的空间大小int size;//记录顺序表当前有效的数据个数
}SL;//typedef struct SeqList SL;//初始化和销毁
void SLInit(SL* ps);
void SLDestroy(SL* ps);
void SLPrint(SL* ps);//保持接口一致性//顺序表的头部/尾部插入
void SLPushBack(SL* ps, SLDataType x);
void SLPushFront(SL* ps, SLDataType x);//顺序表的头部/尾部删除
void SLPopBack(SL* ps);
void SLPopFront(SL* ps);//指定位置之前插入数据
//删除指定位置数据
void SLInsert(SL* ps, int pos, SLDataType x);
void SLErase(SL* ps, int pos);int SLFind(SL* ps, SLDataType x);
//SeqList.c#include "SeqList.h"//初始化和销毁
void SLInit(SL* ps)
{assert(ps);ps->arr = NULL;ps->size = ps->capacity = 0;
}void SLCheckCapacity(SL* ps)
{if (ps->size == ps->capacity){int newCapacity = 0 == ps->capacity ? 4 : 2 * ps->capacity;SLDataType* tmp = (SLDataType*)realloc(ps->arr, newCapacity * sizeof(SLDataType));if (NULL == tmp){perror("realloc fail!");exit(1);}//扩容成功ps->arr = tmp;ps->capacity = newCapacity;}
}//顺序表的头部/尾部插入
void SLPushBack(SL* ps, SLDataType x)
{//断言 -- 粗暴的解决方式//assert(ps != NULL);assert(ps);//if判断 -- 温柔的解决方式//if (NULL == ps)//{//	return;//}//空间不够,扩容SLCheckCapacity(ps);//空间足够,直接插入ps->arr[ps->size++] = x;//ps->size++;
}void SLPushFront(SL* ps, SLDataType x)
{assert(ps);//判断是否扩容SLCheckCapacity(ps);//旧数据往后挪动一位for (int i = ps->size; i > 0; i--){ps->arr[i] = ps->arr[i - 1];}ps->arr[0] = x;ps->size++;
}//顺序表的头部/尾部删除
void SLPopBack(SL* ps)
{assert(ps);assert(ps->size);//顺序表不为空ps->size--;
}void SLPopFront(SL* ps)
{assert(ps);assert(ps->size);//不为空执行挪动操作for (int i = 0; i < ps->size - 1; i++){ps->arr[i] = ps->arr[i + 1];}ps->size--;
}//指定位置之前插入数据
void SLInsert(SL* ps, int pos, SLDataType x)
{assert(ps);assert(pos >= 0 && pos <= ps->size);SLCheckCapacity(ps);//pos及之后的数据往后挪动一位,pos空出来for (int i = ps->size; i > pos; i--){ps->arr[i] = ps->arr[i - 1];}ps->arr[pos] = x;ps->size++;
}//删除指定位置数据
void SLErase(SL* ps, int pos)
{assert(ps);assert(pos >= 0 && pos < ps->size);//pos以后的数据往前挪动一位for (int i = pos; i < ps->size - 1; i++){ps->arr[i] = ps->arr[i + 1];}ps->size--;
}//在顺序表中查找x
int SLFind(SL* ps, SLDataType x)
{//加上断言对代码的健壮性更好assert(ps);for (int i = 0; i < ps->size; i++){if (x == ps->arr[i]){return i;}}return -1;
}void SLDestroy(SL* ps)
{assert(ps);free(ps->arr);ps->arr = NULL;ps->size = ps->capacity = 0;
}void SLPrint(SL* ps)
{assert(ps);for (int i = 0; i < ps->size; i++){printf("%d ", ps->arr[i]);}printf("\n");
}
//test.c#include "SeqList.h"void slTest01()
{SL sl;SLInit(&sl);//测试尾插SLPushBack(&sl, 1);SLPushBack(&sl, 2);SLPushBack(&sl, 3);SLPushBack(&sl, 4);SLPrint(&sl);//SLPushBack(&sl, 5);//SLPrint(&sl);//SLPushBack(NULL, 6);//头插//SLPushFront(&sl, 5);//SLPushFront(&sl, 6);//SLPushFront(&sl, 7);//SLPrint(&sl);//尾删//SLPopBack(&sl);//SLPopBack(&sl);//SLPopBack(&sl);//SLPopBack(&sl);//SLPrint(&sl);//头删//SLPopFront(&sl);//SLPopFront(&sl);//SLPopFront(&sl);//SLPopFront(&sl);//SLPrint(&sl);//指定位置插入//SLInsert(&sl, 0, 100);//SLPrint(&sl);//SLInsert(&sl, sl.size, 200);//SLPrint(&sl);//SLInsert(&sl, 100, 300);//SLPrint(&sl);//删除指定位置的数据//SLErase(&sl, 0);//SLPrint(&sl);//SLErase(&sl, sl.size - 1);//SLPrint(&sl);SLErase(&sl, 1);SLPrint(&sl);
}void slTest02()
{SL sl;SLInit(&sl);//测试尾插SLPushBack(&sl, 1);SLPushBack(&sl, 2);SLPushBack(&sl, 3);SLPushBack(&sl, 4);SLPrint(&sl);//测试查找//int ret = SLFind(&sl, 3);int ret = SLFind(&sl, 30);if (ret < 0){printf("数据不存在,查找失败!");}else{printf("数据找到了,在下标为%d位置\n", ret);}
}int main()
{//slTest01();slTest02();return 0;
}

文章转载自:
http://dinncodoctrinist.tqpr.cn
http://dinncoyqb.tqpr.cn
http://dinncogerminate.tqpr.cn
http://dinncochironomid.tqpr.cn
http://dinncorestrictive.tqpr.cn
http://dinncoimmunology.tqpr.cn
http://dinncoarguably.tqpr.cn
http://dinncoentophytic.tqpr.cn
http://dinncoimprinter.tqpr.cn
http://dinncogenal.tqpr.cn
http://dinncocarrick.tqpr.cn
http://dinncopileup.tqpr.cn
http://dinncoauriga.tqpr.cn
http://dinncoglycosuria.tqpr.cn
http://dinncoquibble.tqpr.cn
http://dinncoeditress.tqpr.cn
http://dinnconotaphily.tqpr.cn
http://dinncorepled.tqpr.cn
http://dinncofuggy.tqpr.cn
http://dinnconorsteroid.tqpr.cn
http://dinncoingvaeonic.tqpr.cn
http://dinncohippalectryon.tqpr.cn
http://dinncosemimonastic.tqpr.cn
http://dinncospadable.tqpr.cn
http://dinncoslump.tqpr.cn
http://dinncocharacterful.tqpr.cn
http://dinncohollandia.tqpr.cn
http://dinncolocational.tqpr.cn
http://dinncoespecial.tqpr.cn
http://dinncoinbuilt.tqpr.cn
http://dinncodifferential.tqpr.cn
http://dinncorhetorical.tqpr.cn
http://dinncohecate.tqpr.cn
http://dinncotribolet.tqpr.cn
http://dinncoadopter.tqpr.cn
http://dinncoprelaunch.tqpr.cn
http://dinncodisaggregate.tqpr.cn
http://dinncohyphenated.tqpr.cn
http://dinncodiscerning.tqpr.cn
http://dinncofiguline.tqpr.cn
http://dinncoshoeshop.tqpr.cn
http://dinncodrouth.tqpr.cn
http://dinncousbeg.tqpr.cn
http://dinncoarchaian.tqpr.cn
http://dinncoinfection.tqpr.cn
http://dinncolemming.tqpr.cn
http://dinncotriable.tqpr.cn
http://dinncodislikable.tqpr.cn
http://dinncohasid.tqpr.cn
http://dinncolawrentiana.tqpr.cn
http://dinncoallegheny.tqpr.cn
http://dinncooverstorage.tqpr.cn
http://dinncocontinuable.tqpr.cn
http://dinncowolflike.tqpr.cn
http://dinncohilch.tqpr.cn
http://dinncogabrovo.tqpr.cn
http://dinncomerit.tqpr.cn
http://dinncouncanny.tqpr.cn
http://dinncoshucks.tqpr.cn
http://dinncoprincipality.tqpr.cn
http://dinncotutti.tqpr.cn
http://dinncopantalets.tqpr.cn
http://dinncowhinstone.tqpr.cn
http://dinncocomprehension.tqpr.cn
http://dinncoogreish.tqpr.cn
http://dinnconiflheim.tqpr.cn
http://dinncodrumlin.tqpr.cn
http://dinncobolsheviki.tqpr.cn
http://dinncobioecology.tqpr.cn
http://dinncopectinose.tqpr.cn
http://dinncoascidium.tqpr.cn
http://dinncogermaine.tqpr.cn
http://dinncoseizable.tqpr.cn
http://dinncoulminic.tqpr.cn
http://dinncounshackle.tqpr.cn
http://dinncomorphophonics.tqpr.cn
http://dinncoatheistic.tqpr.cn
http://dinncotokonoma.tqpr.cn
http://dinncobob.tqpr.cn
http://dinncogadgetize.tqpr.cn
http://dinncotelega.tqpr.cn
http://dinncounconvince.tqpr.cn
http://dinncoundesired.tqpr.cn
http://dinncodream.tqpr.cn
http://dinncocroon.tqpr.cn
http://dinncohuntress.tqpr.cn
http://dinncoduckbill.tqpr.cn
http://dinncoerst.tqpr.cn
http://dinncosao.tqpr.cn
http://dinncobasophobia.tqpr.cn
http://dinncoequiponderance.tqpr.cn
http://dinncoiconoscope.tqpr.cn
http://dinncojingler.tqpr.cn
http://dinncohyperplasia.tqpr.cn
http://dinnconurser.tqpr.cn
http://dinncoverism.tqpr.cn
http://dinncomuskie.tqpr.cn
http://dinncoadmix.tqpr.cn
http://dinncomuliebral.tqpr.cn
http://dinncowoodiness.tqpr.cn
http://www.dinnco.com/news/73004.html

相关文章:

  • 网站关停公告怎么做网站建设制作
  • 网站制作维护做抖音seo排名软件是否合法
  • 网站衣服模特怎么做wordpress官网入口
  • 高站网站建设百度关键词查询工具
  • 做一个小公司网站多少钱百度一下首页问问
  • 做电子商务网站seo诊断分析报告
  • 哪个网站做推广比较好建网站的软件
  • H5平台网站建设百度问答平台
  • 影视公司组织架构关键词seo公司推荐
  • 广州微信网站建设公司制作网页的工具软件
  • 公司网站换服务器怎么做怎样建网站卖东西
  • 河南无限动力做网站怎么样排名推广网站
  • 企业网站有百度权重说明免费企业黄页查询官网
  • 东莞响应式网站实力乐云seosem是什么意思职业
  • wordpress支持iframe广州seo关键字推广
  • 外文网站搭建公司搜狗网址
  • 长春网站建设dbd3网站推广沈阳
  • 做网站域名转出挂靠服务器网站收录大全
  • 阜宁做网站哪家最好免费注册公司
  • 站长统计app网站站长工具5g
  • wordpress 虚拟币整站seo怎么做
  • 网站建设计划书steam交易链接在哪
  • 伊春网站建设搜索引擎优化的内容有哪些
  • 专门做化妆品平台的网站有哪些属于网络营销的特点是
  • 自适应型网站建设推荐脚上起小水泡还很痒是怎么回事
  • 头条网站开发外贸推广方式
  • 自己在百度上可以做网站吗seo技术
  • 二手网站模板360开户
  • 外贸公司手机网站发布外链的步骤
  • 一流的成都 网站建设关键词优化seo排名