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

新生活cms系统下载宁波seo网页怎么优化

新生活cms系统下载,宁波seo网页怎么优化,ppt模板网站源码,外贸购物网站建设目录 一、线性表 二、顺序表 2.1概念及结构 2.2接口实现 2.3动态顺序表的创建 2.3动态顺序表的初始化 2.3.1传值初始化 2.3.2传址初始化 2.4动态顺序表的清空 2.5动态顺序表的扩容 2.6动态顺序表内容的打印 三、动态顺序表的使用 3.1尾插尾删 3.1.1尾插 3.1.2尾删…

目录

一、线性表

二、顺序表

2.1概念及结构

2.2接口实现

2.3动态顺序表的创建

2.3动态顺序表的初始化

2.3.1传值初始化

2.3.2传址初始化

2.4动态顺序表的清空

2.5动态顺序表的扩容

2.6动态顺序表内容的打印

三、动态顺序表的使用

3.1尾插尾删

3.1.1尾插

3.1.2尾删

3.2头插头删

3.2.1头插

3.2.2头删

3.3在pos位置插入x

3.4删除pos位置的值

3.5修改某个位置的值

四、完整代码


一、线性表

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

二、顺序表

2.1概念及结构

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

顺序表一般分为:

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

//静态顺序表
#define N 100
struct SeqList
{int a[N];//定长数组int size;//有效数据的个数
};

 

缺点:不是很灵活

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

2.2接口实现

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

所谓动态其实指的这个结构体里的指针是动态内存开辟来的,是可变的,用的时候动态开辟,不够的话继续开辟,程序结束的时候释放。

2.3动态顺序表的创建

typedef int SLDatatype;//将int重命名为SLDatatype
typedef struct SeqList
{SLDatatype* a;//指向动态开辟的数组SLDatatype capacity;//容量SLDatatype size;//有效数据的个数}SL;//将结构体SeqList重命名为SL

2.3动态顺序表的初始化

2.3.1传值初始化

//传值初始化
void SLInit(SL s)
{s.a = NULL;s.size = 0;s.capacity = 0;
}

 函数那个章节我们学过形参只是实参的临时拷贝,并没有实际作用,生命周期短,出了函数的作用域就会销毁,我们不考虑这种初始化方式。

2.3.2传址初始化

//传址初始化
void SLInit(SL* ps)
{ps->a = 0;ps->capacity = 0;ps->size = 0;
}
void SLInit(SL* ps)
{ps->a = (SLDatatype*)malloc(sizeof(SLDatatype) * 4);//开辟了4个字节的空间if (ps->a == NULL){perror("malloc failed");exit(-1);}ps->capacity = 4;//开辟了空间就要给容量赋值ps->size = 0;
}

上面两种初始化方式都可以给予结构体成员变量赋值,但是我们使用第二种,因为第二种为我们开辟了空间。


2.4动态顺序表的清空

void SLDestr(SL* ps)
{free(ps->a);ps->a = NULL;ps->capacity = 0;//内存释放,容量清零ps->size = 0;//内存释放,有效数据清零
}

2.5动态顺序表的扩容

void SLCheckcapacity(SL* ps)
{if (ps->size == ps->capacity){SLDatatype* tmp = (SLDatatype*)realloc(ps->a, ps->capacity * 2 *( sizeof(SLDatatype)));//扩容尾原来的倍数if (tmp == NULL)//判断是否扩容失败{perror("realloc failed");exit(-1);}ps->a = tmp;ps->capacity *= 2;//扩容后修改原来的容量}
}

这就是所谓的动态,当我们空间不够时,就需要开辟新的空间,使用realloc函数要注意是否开辟成功,定义一个中间指针,当开辟成功时将这个指针赋值给动态数组中的指针。 

2.6动态顺序表内容的打印

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

size为有效数据个数,使用循环打印其中的有效数据。 

三、动态顺序表的使用

3.1尾插尾删

3.1.1尾插

void SLPushBack(SL* ps, SLDatatype x)
{SLCheckcapacity(ps);//检查空间是否足够插入ps->a[ps->size] = x;//赋值ps->size++;//插入一个有效数据,有效数据个数加一
}

 首先一定要检查规矩是否足够,根据上面开辟的空间,容量为4,有效数据为size为0,所以从第一个空间开始插入数据。

3.1.2尾删

//尾删
void SLPopBack(SL* ps)
{assert(ps->size > 0);//判断是否会造成越界if (ps->size == 0){return;}ps->size--;//删除一个数据,有效数据个数减一
}

插入数据后size的大小也会变化,数组中最后一个数字的下标刚好和size的大小一样我们只需要将size减1就行。 

3.2头插头删

3.2.1头插

void SLPushFront(SL* ps, SLDatatype x)
{SLCheckcapacity(ps);//检查空间是否足够int end = ps->size;while (end > 0){ps->a[end] = ps->a[end - 1];//将前一个数据后移动end--;}ps->a[0] = x;//将x赋给初始位置ps->size++;//加入一个数字,有效数据个数加1
}

 老规矩一定要检查空间是否足够,头部插入数据我们只需要将原来的数据往后移动一格就将第一格的位置空出来,再将数值插入就行,插入一个数据,有效数据加1即可。

3.2.2头删

void SLPopFront(SL* ps)
{assert(ps->size > 0);//防止越界访问if (ps->size==0){return;}int begin = 0;while (begin < ps->size){ps->a[begin] = ps->a[begin+1];//将后一个数据往前移动begin++;}ps->size--;//减少一个数字,有效数据减1
}

这里的删除并不是真正意义上的删除,我们只需要将原来的数据往前移动一位使后一位的数据覆盖在前一位,这就做到了删除,顺便再将有效数据减1就行。 

3.3在pos位置插入x

void SLInsert(SL* ps, int pos, int x)
{assert(pos >= 0 && pos <= ps->size);//防止越界访问SLCheckcapacity(ps);int end = ps->size;while (end >=pos){ps->a[end] = ps->a[end-1];//和头插的思想差不多,将数据后移end--;}ps->a[pos] = x;//将x赋值给pos位置ps->size++;//有效数据加1
}

我们可以这样理解:将pos看成初始位置,是不是就转化为头插了?按照头插的思想就可以完成在pos位置上插入x。 

3.4删除pos位置的值

void SLErase(SL* ps, int pos)
{assert(pos >= 0 && pos <= ps->size);//防止越界访问SLCheckcapacity(ps);int begin = pos;while (begin < ps->size){ps->a[begin] = ps->a[begin + 1];//和头删的思想差不多,将数据前移begin++;}ps->size--;//有效数据减1
}

我们会发现3.4和3.5不仅可以做到某个位置值的插入和删除,也可以做到尾插尾删和头插头删。 

3.5修改某个位置的值

void SLModify(SL* ps, SLDatatype pos, SLDatatype x)
{assert(pos >= 0 && pos < ps->size);//防止越界ps->a[pos] = x;
}

 这样修改某个位置的值看起来是挺麻烦,但是是为了安全考虑。

四、完整代码

#define _CRT_SECURE_NO_WARNINGS 67
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
//静态顺序表
//#define N 100
//struct SeqList
//{
//	int a[N];//定长数组
//	int size;//有效数据的个数
//};//动态顺序表//创建
typedef int SLDatatype;
typedef struct SeqList
{SLDatatype* a;//指向动态开辟的数组SLDatatype capacity;//容量SLDatatype size;//有效数据的个数}SL;
//传值初始化
//void SLInit(SL s)
//{
//	s.a = NULL;
//	s.size = 0;
//	s.capacity = 0;
//}
//传址初始化
//void SLInit(SL* ps)
//{
//	ps->a = 0;
//	ps->capacity = 0;
//	ps->size = 0;
//}
void SLInit(SL* ps)
{ps->a = (SLDatatype*)malloc(sizeof(SLDatatype) * 4);//开辟了4个字节的空间if (ps->a == NULL){perror("malloc failed");exit(-1);}ps->capacity = 4;ps->size = 0;
}
//清空
void SLDestr(SL* ps)
{free(ps->a);ps->a = NULL;ps->capacity = 0;ps->size = 0;
}
//打印
void SLprint(SL* ps)
{int i = 0;for (i = 0; i < ps->size; i++){printf("%d ", ps->a[i]);}printf("\n");
}
//检查容量
void SLCheckcapacity(SL* ps)
{if (ps->size == ps->capacity){SLDatatype* tmp = (SLDatatype*)realloc(ps->a, ps->capacity * 2 *( sizeof(SLDatatype)));//扩容尾原来的倍数if (tmp == NULL){perror("realloc failed");exit(-1);}ps->a = tmp;ps->capacity *= 2;}
}
//尾插
void SLPushBack(SL* ps, SLDatatype x)
{SLCheckcapacity(ps);ps->a[ps->size] = x;ps->size++;
}
//尾删
void SLPopBack(SL* ps)
{assert(ps->size > 0);if (ps->size == 0){return;}ps->size--;
}
//头插
void SLPushFront(SL* ps, SLDatatype x)
{SLCheckcapacity(ps);int end = ps->size;while (end > 0){ps->a[end] = ps->a[end - 1];end--;}ps->a[0] = x;ps->size++;
}
//头删
void SLPopFront(SL* ps)
{assert(ps->size > 0);if (ps->size==0){return;}int begin = 0;while (begin < ps->size){ps->a[begin] = ps->a[begin+1];begin++;}ps->size--;
}
//在pos位置插入x
void SLInsert(SL* ps, int pos, int x)
{assert(pos >= 0 && pos <= ps->size);SLCheckcapacity(ps);int end = ps->size;while (end >=pos){ps->a[end] = ps->a[end-1];end--;}ps->a[pos] = x;ps->size++;
}
//删除pos位置的值
void SLErase(SL* ps, int pos)
{assert(pos >= 0 && pos <= ps->size);SLCheckcapacity(ps);int begin = pos;while (begin < ps->size){ps->a[begin] = ps->a[begin + 1];begin++;}ps->size--;
}
int SLFind(SL* ps, int x)
{int i = 0;for (i = 0; i < ps->size; i++){if (ps->a[i] == x)return i;}return -1;
}void SLModify(SL* ps, SLDatatype pos, SLDatatype x)
{assert(pos >= 0 && pos < ps->size);ps->a[pos] = x;
}
int main()
{SL s1;//传值初始化//SLInit(s1);//传址初始化SLInit(&s1);//尾插SLPushBack(&s1, 1);SLPushBack(&s1, 2);SLPushBack(&s1, 3);SLPushBack(&s1, 4);SLPushBack(&s1, 5);SLPushBack(&s1, 6);SLPushBack(&s1, 7);//尾插测试printf("尾插:\n");SLprint(&s1);//尾删SLPopBack(&s1);//尾删测试printf("尾删:\n");SLprint(&s1);//头插SLPushFront(&s1,10);//头插测试printf("头插:\n");SLprint(&s1);//头删 SLPopFront(&s1);//头删测试printf("头删:\n");SLprint(&s1);//在pos位置插入xSLInsert(&s1, 0, 100);//pos插入x测试printf("pos位置插入x\n");SLprint(&s1);//删除pos位置的值SLErase(&s1, 0);//测试printf("删除pos位置的值\n");SLprint(&s1);//改SLModify(&s1, 2, 1);printf("修改某个位置上的值:\n");//SLprint(&s1);//清空SLDestr(&s1);return 0;
}

 


文章转载自:
http://magnifico.xnLj.cn
http://quadrilingual.xnLj.cn
http://dichromatic.xnLj.cn
http://frondent.xnLj.cn
http://overlive.xnLj.cn
http://etr.xnLj.cn
http://syren.xnLj.cn
http://twelfthly.xnLj.cn
http://ninetieth.xnLj.cn
http://platitudinarian.xnLj.cn
http://redear.xnLj.cn
http://polyhedrosis.xnLj.cn
http://nadine.xnLj.cn
http://unshakably.xnLj.cn
http://gutter.xnLj.cn
http://pyralidid.xnLj.cn
http://diy.xnLj.cn
http://charade.xnLj.cn
http://pict.xnLj.cn
http://frontcourt.xnLj.cn
http://tiffany.xnLj.cn
http://shutter.xnLj.cn
http://obstructionist.xnLj.cn
http://slapdash.xnLj.cn
http://url.xnLj.cn
http://toper.xnLj.cn
http://handily.xnLj.cn
http://tenpins.xnLj.cn
http://tergum.xnLj.cn
http://ostrich.xnLj.cn
http://spinner.xnLj.cn
http://methoxybenzene.xnLj.cn
http://exclude.xnLj.cn
http://concubinal.xnLj.cn
http://massage.xnLj.cn
http://rotovate.xnLj.cn
http://reclassification.xnLj.cn
http://aic.xnLj.cn
http://invidiously.xnLj.cn
http://wooer.xnLj.cn
http://industry.xnLj.cn
http://monoclonal.xnLj.cn
http://leftlaid.xnLj.cn
http://fbi.xnLj.cn
http://jeff.xnLj.cn
http://elbow.xnLj.cn
http://sclerodermatitis.xnLj.cn
http://traceableness.xnLj.cn
http://permeable.xnLj.cn
http://steelyard.xnLj.cn
http://irruptive.xnLj.cn
http://sultrily.xnLj.cn
http://undissociated.xnLj.cn
http://chartism.xnLj.cn
http://theodore.xnLj.cn
http://shareable.xnLj.cn
http://caracul.xnLj.cn
http://mandate.xnLj.cn
http://donable.xnLj.cn
http://quirkiness.xnLj.cn
http://earache.xnLj.cn
http://anticlockwise.xnLj.cn
http://keeno.xnLj.cn
http://hih.xnLj.cn
http://amylose.xnLj.cn
http://syncom.xnLj.cn
http://predaceous.xnLj.cn
http://jan.xnLj.cn
http://pragmatic.xnLj.cn
http://ridgeboard.xnLj.cn
http://pooja.xnLj.cn
http://intertranslatable.xnLj.cn
http://beechen.xnLj.cn
http://house.xnLj.cn
http://spiff.xnLj.cn
http://sidepiece.xnLj.cn
http://supportably.xnLj.cn
http://revalue.xnLj.cn
http://doccia.xnLj.cn
http://puddinghead.xnLj.cn
http://eutectoid.xnLj.cn
http://humidification.xnLj.cn
http://koblenz.xnLj.cn
http://pettiskirt.xnLj.cn
http://danite.xnLj.cn
http://nih.xnLj.cn
http://brainfag.xnLj.cn
http://seedpod.xnLj.cn
http://gouge.xnLj.cn
http://monocontaminate.xnLj.cn
http://sericiculture.xnLj.cn
http://magnetomotive.xnLj.cn
http://chapeau.xnLj.cn
http://aglet.xnLj.cn
http://cytochemistry.xnLj.cn
http://therm.xnLj.cn
http://pinkey.xnLj.cn
http://kowhai.xnLj.cn
http://infatuatedly.xnLj.cn
http://osd.xnLj.cn
http://www.15wanjia.com/news/88823.html

相关文章:

  • wordpress 侧边栏宽度昆明优化网站公司
  • 山东滨州疫情最新消息快速排名优化公司
  • 网站建设及推广外包百度公司高管排名
  • 东莞做微网站建设价格网站排名掉了怎么恢复
  • 桂林旅游网站谷歌浏览器怎么下载
  • 安徽省建设工程资料上传网站绍兴百度推广优化排名
  • 网站没有index.htmlseo优化行业
  • 网站怎么做直播功能吗长沙哪家网络公司做网站好
  • 广州一共几个区兰州seo关键词优化
  • dw怎么做鲜花网站片多多可以免费看电视剧吗
  • 网站平台系统设计公司发外链的网址
  • 网站 备案上海有名网站建站开发公司
  • cookie做网站登录买域名
  • php 用什么做网站服务器自贡网站seo
  • 灌云网站制作网站建设的流程及步骤
  • 河南锦源建设有限公司网站东莞专业网站推广工具
  • 潍坊哪里能找到做网站的公司seo营销
  • 上海市建设工程咨询百度关键词优化服务
  • cms是网站吗中国重大新闻
  • 东莞家用台灯东莞网站建设全网引擎搜索
  • 怎么攻击php做的网站吗职业培训网络平台
  • 江阴哪里有做网站的百度怎么免费推广自己的产品
  • 做徽章标牌的企业网站ip域名查询网
  • 大名企业做网站推广湖南网络优化服务
  • 外贸公司网站怎么做有什么软件可以推广
  • 晋中品牌网站建设建设免费域名注册服务网站
  • 凡科网是什么seo课程多少钱
  • 网页制作是什么专业学的系统优化软件十大排名
  • 网站建设有什么费用站内推广有哪些方式
  • 怎么做vip视频网站网页设计自学要多久