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

广州公司网站建设百度上搜索关键词如何在首页

广州公司网站建设,百度上搜索关键词如何在首页,wordpress 安装路径,营销网站建设公司地址文章目录 线性表动态顺序表数组与顺序表 接口实现初始化:尾插:尾删头插头删指定位置插入指定位置删除查找摧毁 完整代码 线性表 线性表是数据结构中最基本、最简单也是最常用的一种数据结构。线性表是指由n个具有相同数据类型的元素组成的有限序列。 线…

文章目录

  • 线性表
  • 动态顺序表
    • 数组与顺序表
  • 接口实现
    • 初始化:
    • 尾插:
    • 尾删
    • 头插
    • 头删
    • 指定位置插入
    • 指定位置删除
    • 查找
    • 摧毁
  • 完整代码

线性表

线性表是数据结构中最基本、最简单也是最常用的一种数据结构。线性表是指由n个具有相同数据类型的元素组成的有限序列

线性表分为顺序表和链表两种实现方式。

  1. 顺序表
    顺序表是线性表的一种实现方式,它在计算机内存中以数组的形式保存数据元素。顺序表的特点是元素在内存中是连续存储的,通过索引可以直接访问元素,因此具有较快的随机访问速度。但是顺序表的长度是固定的,需要提前申请足够的内存空间,并且插入和删除元素时需要移动其他元素,效率较低。
    在这里插入图片描述

  2. 链表
    链表是线性表的另一种实现方式,它通过指针将多个节点串联起来。每个节点包含元素和指向下一个节点的指针,所以链表的内存分布可以是离散的。链表的优点是可以动态地分配内存,插入和删除操作只需要修改指针,效率较高。但是链表的访问速度比较慢,需要遍历节点找到目标位置。
    在这里插入图片描述

本章主要介绍的是顺序表。

动态顺序表

顺序表分为静态顺序表和动态顺序表;

静态顺序表是用定长数组来进行存储元素;
在这里插入图片描述
动态顺序表是利用动态存储开辟的数组:
在这里插入图片描述

数组与顺序表

顺序表和数组在某种程度上可以说是相似的,因为顺序表的基本实现就是数组。顺序表是对数组的一种封装,它在数组的基础上提供了更加灵活的内存管理方式,使得插入、删除等操作更加高效。

接口实现

我们要将函数都包含在一个头文件中,然后用一个源文件来对函数的实现;
结构

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
typedef int SLTypeData;typedef struct SeqList
{SLTypeData* a;int size;  //有效个数int capacity;  //空间大小}SL;

初始化:

void SLInit(SL* ps)
{assert(ps);ps->a = (SLTypeData*)malloc(sizeof(SLTypeData) * 4);if (ps->a == NULL){perror("malloc failed");exit(-1);}ps->size = 0;ps->capacity = 4;
}

对数组先开辟4个空间,然后判断是否开辟成功,成功就对size和容量进行初始化赋值;

尾插:

void AddCapacity(SL* ps)
{assert(ps);SLTypeData* cmp = (SLTypeData*)realloc(ps->a, sizeof(SLTypeData) * (ps->capacity + 3));if (cmp == NULL){perror("realloc failed");exit(-1);}ps->a = cmp;ps->capacity += 3;
}
void SLPushBack(SL* ps, SLTypeData x)
{//满需要扩容if (ps->size == ps->capacity){AddCapacity(ps);}//开始尾插ps->a[ps->size] = x;ps->size++;
}

在这里,由于还有头插和位置插入,所以就写一个函数来进行增加容量;每次容量增加3;尾插只需要在size下标进行赋值,最后再把size++即可;

我们写一个打印函数验证一下:

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

然后在主函数中加以验证:

#include"SeqList.h"int main()
{SL test;SLInit(&test);SLPushBack(&test, 1);SLPushBack(&test, 2);SLPushBack(&test, 3);SLPushBack(&test, 4);SLPushBack(&test, 5);SLPrint(&test);return 0;
}

在这里插入图片描述

尾删

void SLPopBack(SL* ps)
{assert(ps->size > 0);ps->size--;
}

验证:

int main()
{SL test;SLInit(&test);SLPushBack(&test, 1);SLPushBack(&test, 2);SLPushBack(&test, 3);SLPushBack(&test, 4);SLPushBack(&test, 5);SLPrint(&test);SLPopBack(&test);SLPrint(&test);return 0;
}

在这里插入图片描述

头插

void SLPushFront(SL* ps, SLTypeData x)
{assert(ps);//满扩容if (ps->size == ps->capacity){AddCapacity(ps);}//往后移for (int i = ps->size; i > 0; i--){ps->a[i] = ps->a[i-1];}//头插ps->a[0] = x;ps->size++;
}

这里要插入需要对当前数组进行挪移,给第一个元素腾出空间存储;

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);return 0;
}

在这里插入图片描述

头删

void SLPopFront(SL* ps)
{assert(ps);//判断assert(ps->size > 0);//左移for (int i = 0; i < ps->size - 1; i++){ps->a[i] = ps->a[i + 1];}//size减1ps->size--;}

头一个元素删完之后,需要将后面元素向前移动;最后将size–;

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);SLPopFront(&test);SLPrint(&test);return 0;
}

在这里插入图片描述

指定位置插入

//起始位置为1,例如pos=1,那么就是在下标为0的位置插入
void SLInsert(SL* ps, int pos, SLTypeData x)
{assert(ps);assert(pos > 0 && pos <= ps->size + 1); //指定pos范围//满扩容if (ps->size == ps->capacity){AddCapacity(ps);}//位置后移for (int i = ps->size; i > pos - 1; i--){ps->a[i] = ps->a[i - 1];}//插入ps->a[pos - 1] = x;ps->size++;
}

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);SLInsert(&test, 3, 88);SLPrint(&test);return 0;
}

在这里插入图片描述

指定位置删除

void SLErase(SL* ps, int pos)
{assert(ps);assert(pos > 0 && pos <= ps->size);//指定pos范围//左移for (int i = pos - 1; i < ps->size-1; i++){ps->a[i] = ps->a[i + 1];}ps->size--;
}

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);SLInsert(&test, 3, 88);SLPrint(&test);SLErase(&test, 4);SLPrint(&test);return 0;
}

在这里插入图片描述

查找

查找对应的元素,如果有多个元素一样,返回的是最左边的元素;
返回的初始位置为1,例如下标为0,那么返回位置为1;

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

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);int pos = SLFind(&test, 3);printf("3的位置是%d", pos);return 0;
}

在这里插入图片描述

摧毁

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

验证:

int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);SLDestory(&test);SLPrint(&test);return 0;
}

在这里插入图片描述

完整代码

SeqList.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
//动态顺序表
typedef int SLTypeData;typedef struct SeqList
{SLTypeData* a;int size;  //有效个数int capacity;  //空间大小}SL;void SLInit(SL* ps);//顺序表初始化
void SLDestory(SL* ps);//顺序表摧毁
void SLPushBack(SL* ps, SLTypeData x);//尾插
void SLPopBack(SL* ps);//尾删
void SLPushFront(SL* ps, SLTypeData x);//头插
void SLPopFront(SL* ps);//头删
int SLFind(SL* ps, SLTypeData x);//查找
void SLInsert(SL* ps, int pos, SLTypeData x);//插入
void SLErase(SL* ps, int pos);//删除
void SLPrint(SL* ps);//打印

SeqList.c

#define  _CRT_SECURE_NO_WARNINGS 1
#include "SeqList.h"void SLInit(SL* ps)
{assert(ps);ps->a = (SLTypeData*)malloc(sizeof(SLTypeData) * 4);if (ps->a == NULL){perror("malloc failed");exit(-1);}ps->size = 0;ps->capacity = 4;
}void SLDestory(SL* ps)
{free(ps->a);ps->a = NULL;ps->size = ps->capacity = 0;
}//满扩容
void AddCapacity(SL* ps)
{assert(ps);SLTypeData* cmp = (SLTypeData*)realloc(ps->a, sizeof(SLTypeData) * (ps->capacity + 3));if (cmp == NULL){perror("realloc failed");exit(-1);}ps->a = cmp;ps->capacity += 3;
}
void SLPushBack(SL* ps, SLTypeData x)
{//满需要扩容if (ps->size == ps->capacity){AddCapacity(ps);}//开始尾插ps->a[ps->size] = x;ps->size++;
}void SLPopBack(SL* ps)
{assert(ps->size > 0);ps->size--;
}void SLPushFront(SL* ps, SLTypeData x)
{assert(ps);//满扩容if (ps->size == ps->capacity){AddCapacity(ps);}//往后移for (int i = ps->size; i > 0; i--){ps->a[i] = ps->a[i-1];}//头插ps->a[0] = x;ps->size++;
}void SLPopFront(SL* ps)
{assert(ps);//判断assert(ps->size > 0);//左移for (int i = 0; i < ps->size - 1; i++){ps->a[i] = ps->a[i + 1];}//size减1ps->size--;}int SLFind(SL* ps, SLTypeData x)
{assert(ps);for (int i = 0; i < ps->size; i++){if (ps->a[i] == x){return i+1;}}return -1;
}void SLInsert(SL* ps, int pos, SLTypeData x)
{assert(ps);assert(pos > 0 && pos <= ps->size + 1);//满扩容if (ps->size == ps->capacity){AddCapacity(ps);}//位置后移for (int i = ps->size; i > pos - 1; i--){ps->a[i] = ps->a[i - 1];}//插入ps->a[pos - 1] = x;ps->size++;
}void SLErase(SL* ps, int pos)
{assert(ps);assert(pos > 0 && pos <= ps->size);assert(pos > 0);//左移for (int i = pos - 1; i < ps->size-1; i++){ps->a[i] = ps->a[i + 1];}ps->size--;
}void SLPrint(SL* ps)
{assert(ps);for (int i = 0; i < ps->size; i++){printf("%d ", ps->a[i]);}printf("\n");}

test.c

#define  _CRT_SECURE_NO_WARNINGS 1
#include"SeqList.h"int main()
{SL test;SLInit(&test);SLPushFront(&test, 1);SLPushFront(&test, 2);SLPushFront(&test, 3);SLPushFront(&test, 4);SLPushFront(&test, 5);SLPrint(&test);SLDestory(&test);SLPrint(&test);return 0;
}

文章转载自:
http://biscuity.rmyn.cn
http://embryotrophic.rmyn.cn
http://michael.rmyn.cn
http://saliency.rmyn.cn
http://bibliokleptomania.rmyn.cn
http://factorization.rmyn.cn
http://hamartoma.rmyn.cn
http://contraterrene.rmyn.cn
http://epigrammatist.rmyn.cn
http://burb.rmyn.cn
http://provenience.rmyn.cn
http://feverish.rmyn.cn
http://fritillary.rmyn.cn
http://traditionally.rmyn.cn
http://tropaeoline.rmyn.cn
http://haycock.rmyn.cn
http://abortionism.rmyn.cn
http://conferment.rmyn.cn
http://sequestrable.rmyn.cn
http://dustman.rmyn.cn
http://visitor.rmyn.cn
http://lispingly.rmyn.cn
http://calmness.rmyn.cn
http://capnomancy.rmyn.cn
http://hiragana.rmyn.cn
http://derris.rmyn.cn
http://spaciously.rmyn.cn
http://burrawang.rmyn.cn
http://interface.rmyn.cn
http://jokebook.rmyn.cn
http://nononsense.rmyn.cn
http://grosbeak.rmyn.cn
http://puzzler.rmyn.cn
http://essence.rmyn.cn
http://dasymeter.rmyn.cn
http://creamily.rmyn.cn
http://tailrace.rmyn.cn
http://aerotow.rmyn.cn
http://limekiln.rmyn.cn
http://rollock.rmyn.cn
http://embarcation.rmyn.cn
http://whort.rmyn.cn
http://kootenay.rmyn.cn
http://anisodont.rmyn.cn
http://absently.rmyn.cn
http://makeyevka.rmyn.cn
http://unsophistication.rmyn.cn
http://assort.rmyn.cn
http://dynamicfocus.rmyn.cn
http://warmly.rmyn.cn
http://juneau.rmyn.cn
http://playpit.rmyn.cn
http://inscribe.rmyn.cn
http://nonrepetatur.rmyn.cn
http://neurospora.rmyn.cn
http://microinch.rmyn.cn
http://pallid.rmyn.cn
http://superordination.rmyn.cn
http://hendecahedral.rmyn.cn
http://tautology.rmyn.cn
http://hippophagous.rmyn.cn
http://dreamworld.rmyn.cn
http://piezometry.rmyn.cn
http://unbridled.rmyn.cn
http://heartfelt.rmyn.cn
http://scrotocele.rmyn.cn
http://pietas.rmyn.cn
http://bifacial.rmyn.cn
http://flopper.rmyn.cn
http://sideslip.rmyn.cn
http://fanion.rmyn.cn
http://sgi.rmyn.cn
http://millimicrosecond.rmyn.cn
http://rostral.rmyn.cn
http://duckery.rmyn.cn
http://concretively.rmyn.cn
http://ebulliometer.rmyn.cn
http://dyspnea.rmyn.cn
http://nonagenarian.rmyn.cn
http://masthead.rmyn.cn
http://imbed.rmyn.cn
http://weep.rmyn.cn
http://eliminator.rmyn.cn
http://chasm.rmyn.cn
http://sinuation.rmyn.cn
http://docetic.rmyn.cn
http://faa.rmyn.cn
http://joseph.rmyn.cn
http://boulogne.rmyn.cn
http://megapod.rmyn.cn
http://antiandrogen.rmyn.cn
http://juruena.rmyn.cn
http://disincline.rmyn.cn
http://bibliolatry.rmyn.cn
http://sinnerite.rmyn.cn
http://slug.rmyn.cn
http://denotation.rmyn.cn
http://pressure.rmyn.cn
http://precatory.rmyn.cn
http://petasos.rmyn.cn
http://www.15wanjia.com/news/90223.html

相关文章:

  • 大型企业网站欣赏舆情分析系统
  • 网站建设首页该放什么提高工作效率的重要性
  • 个人做外贸网站西安百度公司官网
  • 佳木斯网站制作推广联系方式
  • 佛山品牌网站建设南京 seo 价格
  • 哈尔滨做网站费用报价优化网址
  • 做网站 赚钱吗数据分析网页
  • 贵阳哪里可以做网站在线建站平台免费建网站
  • 长沙网站建设有限公司nba最新消息交易
  • 做网站哪家比较好上海最新疫情
  • 什么专业会做网站100个常用的关键词
  • 做移门配件的网站百度发作品入口在哪里
  • 做网站需要成立公司吗天津seo网络营销
  • 的网站建设公司哪家好百度搜索引擎
  • 网站开发验收过程百度官网
  • 国内做任务得数字货币的网站如何进行电子商务网站推广
  • 做网站都用什么工具引流推广怎么做
  • 怎样做网站外部链接佛山seo优化
  • 做婚纱网站是怎么确认主题长沙专业做网站公司
  • 网站建设去哪现在外贸推广做哪个平台
  • 深圳住房建设部网站深圳百度关键词
  • 北京便宜做网站初学seo网站推广需要怎么做
  • 网站 备案 初审厦门头条今日新闻
  • 企业网站建设选题的依据及意义东莞网络优化调查公司
  • 做手机网站哪家好北京seo关键词排名优化软件
  • 校园网站建设总体设计上海关键词优化公司哪家好
  • 物流网站建设案例nba最新排名公布
  • 铜陵网站制作sem竞价推广托管代运营公司
  • web设计与应用seo搜索优化专员
  • 网站备案临时关闭怎么操作今日广州新闻头条