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

深圳建工集团百度seo排名技术必不可少

深圳建工集团,百度seo排名技术必不可少,网页美工设计软件,网站建设河南数据结构:顺序表详解 一、 线性表二、 顺序表概念及结构1. 静态顺序表:使用定长数组存储元素。2. 动态顺序表:使用动态开辟的数组存储。三、接口实现1. 创建2. 初始化3. 扩容4. 打印5. 销毁6. 尾插7. 尾删8. 头插9. 头删10. 插入任意位置数据…

数据结构:顺序表详解

  • 一、 线性表
  • 二、 顺序表概念及结构
  • 1. 静态顺序表:使用定长数组存储元素。
  • 2. 动态顺序表:使用动态开辟的数组存储。
  • 三、接口实现
    • 1. 创建
    • 2. 初始化
    • 3. 扩容
    • 4. 打印
    • 5. 销毁
    • 6. 尾插
    • 7. 尾删
    • 8. 头插
    • 9. 头删
    • 10. 插入任意位置数据
    • 11. 删除任意位置数据
    • 12. 查找
    • 13. 修改
  • 四:所有代码


在这里插入图片描述


一、 线性表

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

在这里插入图片描述


二、 顺序表概念及结构

顺序表是用一段物理地址连续的存储单元依次存储数据元素的线性结构,一般情况下采用数组存储。在数组上完成数据的增删查改。

顺序表一般可以分为:

1. 静态顺序表:使用定长数组存储元素。

在这里插入图片描述

2. 动态顺序表:使用动态开辟的数组存储。

在这里插入图片描述


三、接口实现

静态顺序表只适用于确定知道需要存多少数据的场景。静态顺序表的定长数组导致N定大了,空间开多了浪费,开少了不够用。所以现实中基本都是使用动态顺序表,根据需要动态的分配空间大小,所以下面我们实现动态顺序表。

基本增删查改接口

//对数据管理 --- 增删查改
void SLInit(SL* ps);			//初始化
void SLDestory(SL* ps);			//释放
void SLPrint(SL* ps);        	//打印
void SLCheakCapacity(SL* ps);	//检查容量 -- 扩容//头插头删 尾插尾删
void SLPushBack(SL* ps, SLDateType x); //尾插
void SLPopBack(SL* ps);				   //尾删
void SLPushFront(SL* ps, SLDateType x);//头插
void SLPopFront(SL* ps);			   //头删//返回下标,没找到返回-1
int SLFind(SL* ps, SLDateType);		   //查找元素,返回下标//在pos位置插入x
void SLInsert(SL* ps, int pos, SLDateType x);	//任意位置插入
//在pos位置删除x
void SLErase(SL* ps, int pos);					//任意位置删除void SLModify(SL* ps, int pos, SLDateType x);//修改

1. 创建

由于在实际工程中,项目的实现都是采用模块化进行实现的。所以在此处博主也采用了模块化的方式进行实现。
在这里插入图片描述

#pragma once#include <stdio.h>
#include <assert.h>
#include <stdlib.h>//动态顺序表
typedef int SLDateType;
typedef struct SeqList
{SLDateType* a;//指向动态开辟的数组int size;	//有效数据的个数int capacity;//容量空间的大小
}SL;

为了后续好修改类型数据,在此采用typedef将结构体类型struct SeqList 重新命名为SL
在实际开发过程中,为了开发人员更好的输入数据,一般我们会将输入数据的数据类型重命名为SLDateType。(在本篇博客中,采用typedef将其数据类型int重命名为SLDateType


2. 初始化

初始化时,理论上我们只需要开辟一个空间并置为空指针,并将结构体中的数据全部初始化为0即可。
但在实际开发过程中,我们一般会开辟一定大小的空间(本篇博客开4个空间,但具体开多少,各位可自行选择)。

代码实现:

void SLInit(SL* ps)
{assert(ps);ps->a = (SLDateType*)malloc(4 * sizeof(SLDateType));//开辟4个空间if (ps->a == NULL){perror("malloc");exit(-1);}//开辟成功ps->capacity = 4;//开辟多少空间,容量变为多少ps->size = 0;
}

3. 扩容

在后续我们插入数据时,已开辟容量可能已经无法满足需求了。这是就需要扩容。
那一次扩到多少呢?
在实际开发过程中我们一般是扩到原有空间的两倍。(当然你也可以开1000倍,只要后台空间足够大)

代码实现:

void SLCheakCapacity(SL* ps)
{assert(ps);if (ps->size == ps->capacity){//开辟空间X2SLDateType* tmp = (SLDateType*)realloc(ps->a, ps->capacity * sizeof(SLDateType) * 2);if (tmp == NULL){perror("realloc");exit(-1);}//开辟成功ps->a = tmp;ps->capacity *= 2;}
}

4. 打印

上述函数定义完成后,我们通常需要测试打印以下相关数据,来判断相关函数定义是否成功.

代码实现:

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

5. 销毁

由于上述空间是动态开辟的。所以当我们使用完时,要及时销毁,释放空间。

代码实现:

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

6. 尾插

尾插:在尾部插入一个数据。
在这里插入图片描述

但是在数据的尾部插入一个数据时,我们需要考虑一个问题:原有空间是否可以容纳新的数据,是否需要扩容。
所以我们在插入数据时,要先调用 SLCheakCapacity函数来检查是否需要扩容。

代码实现:

void SLPushBack(SL* ps, SLDateType x)
{assert(ps);SLCheakCapacity(ps);//检查是否需要扩容ps->a[ps->size] = x;ps->size++;
}

7. 尾删

尾删:删除尾部最后的一个元素。
在这里插入图片描述

但尾删同样也要考虑一个问题,空间中是否还有数据给我们删除。
所以在进行尾删时,我们可以采用assert函数断言空间中还有数据。

代码实现:

void SLPopBack(SL* ps)
{assert(ps);assert(ps->size >= 0);//断言空间中还有元素ps->size--;//下标减1
}

在删除数据时,我们不用将原有数据删除。只需要下标减1即可。
原因在于我们时根据下标来使用数据的,当下标减1后,尾部最后一个数据便无法进行访问。

Tips:

  • 越界是不一定报错的,系统对越界的检查是一种设岗抽查。
  • 以VS2022为例,微软公司在数据的开始前和结尾后的一小段空间设有一些特殊值。当程序结束或内存空间释放时,编译器就会检查这些值是否发生改变, 从而触发程序的保护机制。但如果这些值没有发生改变,即使发生越界访问,程序也不会报错。就像如果你酒驾,交警只在二环设关卡,但只要你不去二环,你就没事不会被发现。(每个编译器略有差异)

8. 头插

头插:在数据最开始地方插入数据。
在这里插入图片描述

同样,头插也要调用 SLCheakCapacity函数来检查空间是否足够,是否需要扩容。

代码实现:

void SLPushFront(SL* ps, SLDateType x)
{assert(ps);SLCheakCapacity(ps);//检查是否需要扩容//移动数据int i = ps->size-1;while (i >= 0){ps->a[i + 1] = ps->a[i];i--;}//移动数据完成,插入元素。同时有效个数加1ps->a[0] = x;ps->size++;
}

9. 头删

头删:删除数据最开始的元素。
在这里插入图片描述

思路和头插类似,只要下标从1开始,所有数据依次向前移动1位,再把有限个数减1即可。
同时头删也需要使用assert函数断言原有空间中还有数据可以删除。

代码实现:

void SLPopFront(SL* ps)
{assert(ps);assert(ps->size >= 0);//空间中还有数据可以删除//移动数据for (int begin = 1; begin < ps->size; begin++){ps->a[begin - 1] = ps->a[begin];}ps->size--;//有效个数减1
}

10. 插入任意位置数据

由于顺序表要求数据是连续存放的,所以我们只需要找到输入位置的下标pos即可。

【代码思路】:首先我们要检查输入下标是否合法,是有效下标;并检查是否有足够空间来容纳新数据,是否需要扩容。之后从输入的数据下标开始,所有元素向后移动一位,并把新数据插入到下标为pos处即可。

代码实现:

void SLInsert(SL* ps, int pos, SLDateType x)
{assert(ps);assert(pos >= 0 && pos <= ps->size);//检查下标是否合法SLCheakCapacity(ps);  //检查空间是否足够//移动数据int end = ps->size - 1;while (end >= pos){ps->a[end + 1] = ps->a[end];end--;}ps->a[pos] = x;ps->size++;
}

11. 删除任意位置数据

【代码思路】:和插入任何位置数据思想类似。首先我们要检查输入下标pos是否合法。之后从输入下标开始,后一个元素拷贝到前一个元素空间。

代码实现:

void SLErase(SL* ps, int pos)
{assert(ps);assert(pos >= 0 && pos < ps->size);//下标是否合法//移动数据int begin = pos+1;while (begin < ps->size){ps->a[begin - 1] = ps->a[begin];begin++;}ps->size--;
}

12. 查找

【代码思路】:要查找某个元素。由于这里只是最简单的查找,我们直接暴力查找,遍历整个数组返回下标即可。更为复杂的数据查找,会有更高阶的数据结构来实现。

代码实现:

int SLFind(SL* ps, SLDateType x)
{assert(ps);for (int i = 0; i < ps->size; i++){if (x == ps->a[i])return i;}return -1;
}

13. 修改

【代码思路】: 要实现修改数据,我们只需要先判断输入下标是否合法。在将对应下标数据进行修改即可。

代码实现:

void SLModify(SL* ps, int pos, SLDateType x)
{assert(ps);assert(pos >= 0 && pos < ps->size);ps->a[pos] = x;
}

四:所有代码

SeqList.h源文件

#include <assert.h>
#include <stdlib.h>//动态顺序表
typedef int SLDateType;
typedef struct SeqList
{SLDateType* a;int size;int capacity;
}SL;//对数据管理 --- 增删查改
void SLInit(SL* ps);
void SLDestory(SL* ps);
void SLPrint(SL* ps);
void SLCheakCapacity(SL* ps);//头插头删 尾插尾删
void SLPushBack(SL* ps, SLDateType x);
void SLPopBack(SL* ps);
void SLPushFront(SL* ps, SLDateType x);
void SLPopFront(SL* ps);//返回下标,没找到返回-1
int SLFind(SL* ps, SLDateType);//在pos位置插入x
void SLInsert(SL* ps, int pos, SLDateType x);
//在pos位置删除x
void SLErase(SL* ps, int pos);void SLModify(SL* ps, int pos, SLDateType x);

SeqList.c头文件

#define _CRT_SECURE_NO_WARNINGS#include "SeqList.h"void SLInit(SL* ps)
{assert(ps);ps->a = (SLDateType*)malloc(4 * sizeof(SLDateType));if (ps->a == NULL){perror("malloc");exit(-1);}//开辟成功ps->capacity = 4;ps->size = 0;
}void SLDestory(SL* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = ps->size = 0;
}void SLPrint(SL* ps)
{assert(ps);for (int i = 0; i < ps->size; i++){printf("%d ", ps->a[i]);}printf("\n");
}void SLCheakCapacity(SL* ps)
{assert(ps);if (ps->size == ps->capacity){SLDateType* tmp = (SLDateType*)realloc(ps->a, ps->capacity * sizeof(SLDateType) * 2);if (tmp == NULL){perror("realloc");exit(-1);}ps->a = tmp;ps->capacity *= 2;}
}void SLPushBack(SL* ps, SLDateType x)
{assert(ps);/*SLCheakCapacity(ps);ps->a[ps->size] = x;ps->size++;*/SLInsert(ps, ps->size, x);
}void SLPopBack(SL* ps)
{assert(ps);assert(ps->size >= 0);/*ps->size--;*/SLErase(ps, 0);
}void SLPushFront(SL* ps, SLDateType x)
{assert(ps);SLCheakCapacity(ps);//移动数据/*int i = ps->size-1;while (i >= 0){ps->a[i + 1] = ps->a[i];i--;}ps->a[0] = x;ps->size++;*/SLInsert(ps, 0, x);
}void SLPopFront(SL* ps)
{assert(ps);assert(ps->size >= 0);/*for (int begin = 1; begin < ps->size; begin++){ps->a[begin - 1] = ps->a[begin];}ps->size--;*/SLErase(ps, 0);
}int SLFind(SL* ps, SLDateType x)
{assert(ps);for (int i = 0; i < ps->size; i++){if (x == ps->a[i])return i;}return -1;
}void SLInsert(SL* ps, int pos, SLDateType x)
{assert(ps);assert(pos >= 0 && pos <= ps->size);SLCheakCapacity(ps);int end = ps->size - 1;while (end >= pos){ps->a[end + 1] = ps->a[end];end--;}ps->a[pos] = x;ps->size++;}void SLErase(SL* ps, int pos)
{assert(ps);assert(pos >= 0 && pos < ps->size);int begin = pos+1;while (begin < ps->size){ps->a[begin - 1] = ps->a[begin];begin++;}ps->size--;
}void SLModify(SL* ps, int pos, SLDateType x)
{assert(ps);assert(pos >= 0 && pos < ps->size);ps->a[pos] = x;
}

在这里插入图片描述
在这里插入图片描述

http://www.hrbkazy.com/news/36193.html

相关文章:

  • 商城网站建设如何交谈百度地图人工电话
  • 模拟网站平台怎么做seo优化搜索推广
  • 王爷太能作全文免费阅读怎么做优化关键词
  • 安徽网站定制上海优化seo公司
  • 苏州木渎做网站网站建设推广
  • wix怎么做网站教程简单网页设计模板html
  • 做室内设计的网站跟我学seo
  • 建站平台石家庄盘古谷歌搜索引擎香港免费入口
  • php网站连接数据库b2b平台有哪些网站
  • wordpress多说评论插件seo教程技术
  • wordpress主题汉化中文seo技术培训江门
  • 网站文件保护怎么做青岛关键词排名提升
  • 万网 填写网站备案信息企业seo顾问公司
  • 网站后台html页面关键词搜索排名推广
  • 网页建设与网站设计心德体会交换友情链接
  • 软件开发可以做网站么网站建设的意义和作用
  • 北京做网站建设的公司有哪些网址域名ip查询
  • 安阳网站建设优化我国的网络营销公司
  • 三亚今天最新通知贵港网站seo
  • 黄埔企业网站建设淘宝怎么优化关键词步骤
  • 广州微网站建设效果重庆seo哪个强
  • wordpress 百度自然搜索排名优化</a> </li> <li> <a href="/news/36166.html">钢材销售都在哪个网站做网络推广员好做吗</a> </li> <li> <a href="/news/36165.html">网站布局有哪些网上推广平台</a> </li> <li> <a href="/news/36164.html">网站建设 启象科技google谷歌搜索引擎</a> </li> <li> <a href="/news/36163.html">自己怎么做云购网站吗域名搜索</a> </li> <li> <a href="/news/36162.html">网站建站一本通2345网址导航官网下载安装</a> </li> <li> <a href="/news/36161.html">网站程序调试模式怎么做客户管理软件</a> </li> <li> <a href="/news/36160.html">湖北省建设厅信息网站2345网址导航浏览器</a> </li> <li> <a href="/news/36159.html">网站开发多少钱一天是搜索平台</a> </li> </div> </article> </main> </div> </div> <aside id="secondary" class="widget-area sidebar"> <div class="widget widget_posts_thumbnail" style="margin-top:6px;"> <h2 class="widget-title">最新文章</h2> <ul> <li class="clear"> <a href="/news/37948.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/徐州信息港网站seo分析案例" alt=" 徐州信息港网站seo分析案例" /> </div> </a> <div class="entry-wrap"> <a href="/news/37948.html" rel="bookmark"> 徐州信息港网站seo分析案例</a> <div class="entry-meta">2025/7/16 20:23:00</div></div> </li> <li class="clear"> <a href="/news/37947.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/任何查询网站有没有做404怎样下载优化大师" alt=" 任何查询网站有没有做404怎样下载优化大师" /> </div> </a> <div class="entry-wrap"> <a href="/news/37947.html" rel="bookmark"> 任何查询网站有没有做404怎样下载优化大师</a> <div class="entry-meta">2025/7/16 20:22:29</div></div> </li> <li class="clear"> <a href="/news/37946.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/网站开发 旅游推广赚佣金的软件排名" alt=" 网站开发 旅游推广赚佣金的软件排名" /> </div> </a> <div class="entry-wrap"> <a href="/news/37946.html" rel="bookmark"> 网站开发 旅游推广赚佣金的软件排名</a> <div class="entry-meta">2025/7/16 20:21:59</div></div> </li> <li class="clear"> <a href="/news/37945.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/南宁网站建设加q.479185700西安做网站的网络公司" alt=" 南宁网站建设加q.479185700西安做网站的网络公司" /> </div> </a> <div class="entry-wrap"> <a href="/news/37945.html" rel="bookmark"> 南宁网站建设加q.479185700西安做网站的网络公司</a> <div class="entry-meta">2025/7/16 20:20:58</div></div> </li> <li class="clear"> <a href="/news/37944.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/专业的集团网站建设长沙网站seo收费标准" alt=" 专业的集团网站建设长沙网站seo收费标准" /> </div> </a> <div class="entry-wrap"> <a href="/news/37944.html" rel="bookmark"> 专业的集团网站建设长沙网站seo收费标准</a> <div class="entry-meta">2025/7/16 20:20:28</div></div> </li> <li class="clear"> <a href="/news/37943.html" rel="bookmark"> <div class="thumbnail-wrap"> <img width="120" height="80" src="/imgs/网站100m空间北京seo排名外包" alt=" 网站100m空间北京seo排名外包" /> </div> </a> <div class="entry-wrap"> <a href="/news/37943.html" rel="bookmark"> 网站100m空间北京seo排名外包</a> <div class="entry-meta">2025/7/16 20:19:57</div></div> </li> </ul> </div> <div class="leftdiv2"> </div> </aside> </div> <footer id="colophon" class="site-footer"> <div class="clear"></div> <div id="site-bottom" class="clear"> <div class="container"> <div class="menu-m_footer-container"> <ul id="footer-menu" class="footer-nav"> <li> <strong> <a href="/">哈卡滋游介绍</a></strong> </li> <li> <strong> <a href="/">商务合作</a></strong> </li> <li> <strong> <a href="/">免责声明</a></strong> </li> </ul> </div> <div class="site-info"> <p>CopyRight © <a href="/">哈卡滋游</a>版权所有 </p> </div> </div> </div> </footer> </div> <div id="back-top"> <a href="#top" title="返回顶部"> <svg width="38" height="38" viewbox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect width="48" height="48" fill="white" fill-opacity="0.01" /> <path d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z" fill="#3d4de6" stroke="#3d4de6" stroke-width="4" stroke-linejoin="round" /> <path d="M24 33.5V15.5" stroke="#FFF" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" /> <path d="M33 24.5L24 15.5L15 24.5" stroke="#FFF" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" /></svg> </a> </div> <script src='/templates/nzzt/js/common.js'></script> <script> $(function(){ $('.source_url').text('原文地址:https://blog.csdn.net/Zhenyu_Coder/article/details/132006417'); }); /*$('.source_url').on("click",function() { window.open('https://blog.csdn.net/Zhenyu_Coder/article/details/132006417', '_blank'); });*/ </script> </body> </html>