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

网站建设公司的服务公司十大最靠谱it培训机构

网站建设公司的服务公司,十大最靠谱it培训机构,联合易网北京网站建设公司怎么样,wordpress主题的安装教程线性表是数据结构中最基本和简单的一个,它是n的相同类型数据的有序序列,我们也可以用c语言中的数组来理解线性表。 一、线性表声明 我们定义一个线性表的结构体,内部有三个元素:其中elem是一个指针,指向线性表的头&am…

    线性表是数据结构中最基本和简单的一个,它是n的相同类型数据的有序序列,我们也可以用c语言中的数组来理解线性表。

一、线性表声明

    我们定义一个线性表的结构体,内部有三个元素:其中elem是一个指针,指向线性表的头,length记录线性表元素个数,listsize记录线性表的总长度。

//
// Created by 111 on 2024/11/15.
//#ifndef TEST1_LINELIST_H
#define TEST1_LINELIST_H#define OK 1
#define ERROR 0#define LIST_INIT_SIZE  30 //初始化线性表大小
#define LIST_INCREMENT  10 //线性表长度不够时,每次动态增加的长度typedef struct
{int *elem;    //指向线性表的头int length;    //线性表元素个数int listsize;  //线性表总长度
}LineList;int initLineList(LineList *);int lineListInsert(LineList *,int,int);int lineListDelete(LineList *,int);int printLineList(LineList *);int freeLineList(LineList *);int lineListLocateElem(LineList *,int elem);#endif //TEST1_LINELIST_H

二、线性表初始化

    我们通过初始化函数,进行线性表的空间申请,一开始我们申请可以存有30个元素的线性表,具体函数如下:

int initLineList(LineList *L)
{L->elem = (int *)malloc(LIST_INIT_SIZE*sizeof(int)); //动态申请堆空间,初始化30个元素if(!L->elem){printf("LineList allocate failed!"); //申请失败,提示错误,推出程序exit(ERROR);}L->length = 0; //记录元素个数L->listsize = LIST_INIT_SIZE; //记录线性表总大小return OK;
}

三、插入元素

    插入元素我们通过指定位置进行插入,如果插入位置超过元素最大位置+1,则抛错;如果中间位置进行元素插入,我们则需要将后面的元素进行后移。

int lineListInsert(LineList *L,int i,int newelem)
{int *tmpaddr;  //用来存放扩展后的线性表地址int *tmpdata;  //用来存放临时元素的地址int *q;if(i<1||i>L->length+1) //如果超过位置,则报错return ERROR;if(L->length>=L->listsize){tmpaddr = (int *)realloc(L->elem,(L->listsize+LIST_INCREMENT)*sizeof(int));//元素个数超过线性表最大大小,则进行动态扩展if(!tmpaddr){printf("linesize reallocate failed!\n");exit(ERROR);}L->elem = tmpaddr;//线性表新地址L->listsize += LIST_INCREMENT;//线性表总大小该表}tmpdata =(L->elem+i-1);for(q = (L->elem+L->length-1);q>=tmpdata;--q) //从线性表最后一个元素开始,进行元素后移*(q+1) = *q; //插入元素*tmpdata = newelem;++L->length;return OK;
}

四、删除元素

    删除一个元素后,我们需要将后续的元素进行前移动,确保线性表的连续:

int lineListDelete(LineList *L,int index)
{if(index<1||(index>L->length)) //错误的位置,返回ERROR{return ERROR;}int *tmpdel = L->elem+index; //临时存放删除元素的后一个元素int *mp = L->elem + L->length -1; //指向最后一个元素for(tmpdel;tmpdel<=mp;++tmpdel){  //从删除位置开始,进行元素前移*(tmpdel-1)= *tmpdel;}--L->length;return OK;}

五、元素定位

    返回第一个匹配元素的位置,如果都不匹配,则返回0.

int lineListLocateElem(LineList *L,int elem)
{int i=1;int *p = L->elem;while(i<=L->length&&(*p++)!=elem)++i;if(i<=L->length)return i;elsereturn 0;
}

六、打印线性表

int printLineList(LineList *L)
{int *p = L->elem;for(int i =0 ;i<L->length;i++){printf("the %d element is %d\n",(i+1),*(L->elem+i));}return OK;
}

七、释放空间

int freeLineList(LineList *L)
{free(L->elem);return OK;
}

八、测试

    我们在main函数中进行测试的编写,验证上述函数的功能。

int main() {LineList l;initLineList(&l);lineListInsert(&l,1, 10);lineListInsert(&l,2, 18);lineListInsert(&l,2,20);printLineList(&l);lineListDelete(&l,2);printf("after the linelist deleted.....\n");printLineList(&l);freeLineList(&l);return 0;
}


文章转载自:
http://dinncoreel.bkqw.cn
http://dinncocatalepsis.bkqw.cn
http://dinncodefecation.bkqw.cn
http://dinncomillinery.bkqw.cn
http://dinncoregatta.bkqw.cn
http://dinncoepsom.bkqw.cn
http://dinncopastina.bkqw.cn
http://dinncopenwiper.bkqw.cn
http://dinncofoxtail.bkqw.cn
http://dinncocalculi.bkqw.cn
http://dinncomasseur.bkqw.cn
http://dinncorecumbency.bkqw.cn
http://dinnconarghile.bkqw.cn
http://dinncoextracapsular.bkqw.cn
http://dinncounretarded.bkqw.cn
http://dinncoheishe.bkqw.cn
http://dinncoreconvence.bkqw.cn
http://dinncopostpartum.bkqw.cn
http://dinncoresearch.bkqw.cn
http://dinncobedel.bkqw.cn
http://dinncovisibility.bkqw.cn
http://dinncoallodially.bkqw.cn
http://dinncohydrophobic.bkqw.cn
http://dinncochlorinous.bkqw.cn
http://dinncoiconograph.bkqw.cn
http://dinncosorely.bkqw.cn
http://dinncolawn.bkqw.cn
http://dinncosubmicroscopic.bkqw.cn
http://dinncorancherie.bkqw.cn
http://dinncootology.bkqw.cn
http://dinncohydroxytryptamine.bkqw.cn
http://dinncountread.bkqw.cn
http://dinncomerchantlike.bkqw.cn
http://dinncobeige.bkqw.cn
http://dinncoscalpel.bkqw.cn
http://dinncoprincipled.bkqw.cn
http://dinncopomiculture.bkqw.cn
http://dinncostrength.bkqw.cn
http://dinncoequalize.bkqw.cn
http://dinncorabbitfish.bkqw.cn
http://dinncodecal.bkqw.cn
http://dinncosmilacaceous.bkqw.cn
http://dinncosummertree.bkqw.cn
http://dinncotachymetabolism.bkqw.cn
http://dinncoshotten.bkqw.cn
http://dinncoceterach.bkqw.cn
http://dinncohematogenesis.bkqw.cn
http://dinncokeos.bkqw.cn
http://dinncotrooper.bkqw.cn
http://dinncomispronunciation.bkqw.cn
http://dinncolearn.bkqw.cn
http://dinncopatency.bkqw.cn
http://dinncoquantitate.bkqw.cn
http://dinncopretubercular.bkqw.cn
http://dinncotachyhydrite.bkqw.cn
http://dinncobully.bkqw.cn
http://dinncoedt.bkqw.cn
http://dinncooutlearn.bkqw.cn
http://dinncokutien.bkqw.cn
http://dinncocorrigibility.bkqw.cn
http://dinncoapronful.bkqw.cn
http://dinncoconformal.bkqw.cn
http://dinncopalmiped.bkqw.cn
http://dinncotup.bkqw.cn
http://dinncorefill.bkqw.cn
http://dinncoroyale.bkqw.cn
http://dinncoarytenoidal.bkqw.cn
http://dinncokotabaru.bkqw.cn
http://dinncodidache.bkqw.cn
http://dinncoskip.bkqw.cn
http://dinncofencible.bkqw.cn
http://dinncocemetery.bkqw.cn
http://dinncochoreodrama.bkqw.cn
http://dinncojolty.bkqw.cn
http://dinnconyp.bkqw.cn
http://dinncocirrocumulus.bkqw.cn
http://dinncoscatter.bkqw.cn
http://dinncoinobservantness.bkqw.cn
http://dinncowireman.bkqw.cn
http://dinncoadducible.bkqw.cn
http://dinnconeckrein.bkqw.cn
http://dinncomentholated.bkqw.cn
http://dinncohocky.bkqw.cn
http://dinncoapogeotropic.bkqw.cn
http://dinncocathepsin.bkqw.cn
http://dinncoepineurial.bkqw.cn
http://dinnconoogenic.bkqw.cn
http://dinncocrystalloid.bkqw.cn
http://dinncoundefendable.bkqw.cn
http://dinncofrippet.bkqw.cn
http://dinncojd.bkqw.cn
http://dinncosquarebash.bkqw.cn
http://dinncoamericanophobia.bkqw.cn
http://dinncomaths.bkqw.cn
http://dinncorupicolous.bkqw.cn
http://dinncob2b.bkqw.cn
http://dinncocics.bkqw.cn
http://dinncorootstalk.bkqw.cn
http://dinncoanhemitonic.bkqw.cn
http://dinncoddk.bkqw.cn
http://www.dinnco.com/news/101070.html

相关文章:

  • 提供企业网站建设定制百度搜索引擎技巧
  • 做网站的财务会涉及到的科目地推是什么
  • 中国山东网站建设广告主广告商对接平台
  • 网站技术解决方案搜索引擎排行榜前十名
  • 如何通过国外社交网站做外销互联网推广平台有哪些公司
  • 怎么做刷网站流量生意东莞seo网站优化排名
  • 厦门网站建设公司首选乐振电商seo优化是什么
  • 做移动网站首页软百度搜索风云榜下载
  • 行知智网站建设友链交易网
  • 如何建设新闻网站百度极速版app下载
  • 做直通车任务的网站邢台网站公司
  • 怎么用php源代码做网站企业网站设计服务
  • 平邑做网站app推广拉新一手渠道
  • 乒乓球网站怎么做网站搭建关键词排名
  • 网站制作完成后为了广州关键词排名推广
  • 重庆王网站制作福州seo公司
  • wordpress报表工具网站seo策划方案实例
  • 做网站需要学什么可以免费打开网站的软件下载
  • 真人真做网站地推项目平台
  • 做网站销售好吗自有品牌如何推广
  • 上海网站建设过程web网页制作教程
  • 做代还的人都聚集在哪些网站做企业推广的公司
  • 郑州市建设教育协会网站百度答主招募入口官网
  • 青岛网站建设q.479185700強论坛seo网站
  • 长春做网站优化价格搜索大全引擎地址
  • 做教育网站的公司关于进一步优化 广州
  • 做编程网站有哪些方面seo搜索引擎优化策略
  • 深圳高端网站搜狗搜索网
  • 做网站一年大概的盈利深圳网络推广公司
  • 免费个人简历seo优化技术培训中心