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

德阳市建设局网站地址免费画图网站

德阳市建设局网站地址,免费画图网站,最新新闻热点300字,广而告之微信推广平台定义顺序表是一种随机存储都结构#xff0c;其特点是表中的元素的逻辑顺序与物理顺序相同。假设线性表L存储起始位置为L(A)#xff0c;sizeof(ElemType)是每个数据元素所占的存储空间的大小#xff0c;则线性表L所对应的顺序存储如下图。顺序表的优缺点优点#xff1a;随机…定义顺序表是一种随机存储都结构其特点是表中的元素的逻辑顺序与物理顺序相同。假设线性表L存储起始位置为L(A)sizeof(ElemType)是每个数据元素所占的存储空间的大小则线性表L所对应的顺序存储如下图。顺序表的优缺点优点随机存储表中的任意元素其存储位置可以用一个简单、直观的公式来表示。存储密度高每个结点只存储数据元素。缺点在做插入或删除元素时需要移动大量元素。操作相对复杂必然导致空间的浪费。静态顺序表的构建在静态分配时由于数组的大小和空间事先已经固定好一旦空间占满再加入新的数据就会产生溢出进而导致进程崩溃。#define MaxSize 100 //顺序表可能达到的最大长度 typedef int ElemType; typedef struct{ElemType data[MaxSize]; //顺序表的元素int length; //当前的长度 }List; //顺序表的类型定义注意线性表中元素的位置是从1开始的而数组中的元素的下标是从0开始的。动态顺表的构建#define MaxSize 100 //顺序表可能达到的最大长度 typedef int ElemType; typedef struct{ElemType* data; //存储空间的基址int length; //当前的长度 }List; //顺序表的结构类型为ListC的初始动态分配语句list.data (ElemType*)malloc(sizeof(ElemType)*MaxSize); //动态开辟空间 c语言C的初始动态分配语句list.data new ElemType[MaxSize]; //动态开辟空间 (c)注意动态分配并不是链式存储它同样属于顺序存储结构物理结构没有变化依然是随机存储方式只是分配的空间大小可以在运行时动态决定。动态顺序表的常见操作插入插入新元素的图解void Insert(List *list, int index, int value){ //插入(在第index位置插入value)if (index 1 || index list-length 1){ //判断范围是否有效printf(插入失败位置输入错误\n);return;}if (list-length MaxSize){ //空间已满无法插入printf(插入失败顺序表已满\n);return;}for (int i list-length; i index; i--){ //将第index个元素及之后的元素后移list-data[i] list-data[i - 1];}list-data[index - 1] value; //将位置index放入valuelist-length; //线性表长度加一printf(插入成功\n);return; }线性表插入算法的平均时间复杂度为O(N)。取值根据下标来查找元素void GetElem(List list, int index){ //取值(用下标找元素)if (index 0 index list.length){printf(要查找的第%d个元素是%d\n, index, list.data[index - 1]);}else{printf(输入的值有误\n);} }查找根据所给的元素来遍历顺序表来寻找void LocateElem(List list, int value){ //查找(用值找下标)for (int i 0; i list.length; i){if (value list.data[i]){printf(%d是本表中的第%d元素\n, value, i 1);return;}}printf(找不到该元素\n);return; }线性表按值查找算法的平均时间复杂度为O(N)。删除删除元素的图解void Delete(List *list, int index){ //删除(删除指定的第几个元素)if (index 1 || index list-length) { //判断index的范围是否有效printf(删除失败输入的数值有误\n);return;}for (int i index - 1; i list-length - 1; i){ //将第index个位置后的元素前移list-data[i] list-data[i 1];}list-length--; //线性表长度减一printf(删除成功\n);return; }线性表删除算法的平均时间复杂度为O(N)。销毁void Clear(List *list){ //销毁list-length 0; //将顺序表的长度设为0free(list-data); //释放malloc申请的空间printf(顺序表已销毁\n); }划分已第一个元素为界比它小的元素放在它的前面比它大的元素放在它的后面void ListSort(List *list){ //划分(已第一个元素为界前面比它小后面比它大)int i 0, j 0;int temp, k;temp list-data[0];for (i 1; i list-length; i){if (temp list-data[i]){k list-data[i];for (j i; j 0; j--){list-data[j] list-data[j - 1];}list-data[0] k;}}printf(划分成功\n);return; }单值化单值化类似与去掉顺序表中重复的元素void DeleteSame(List *list){ //单值化(去掉重复的元素)int i 0;while (i list-length){for (int j i 1; j list-length; j)while (list-data[i] list-data[j]){for (int k j; k list-length; k)list-data[k] list-data[k 1];list-length--;}i;}printf(单值化完成\n);return; }源码SeqList.h#include stdio.h #include windows.h #include malloc.h#define MaxSize 100 typedef int ElemType; typedef struct{ElemType* data; //动态顺序表int length; }List;void menu(); void PutList(); void GetElem(); void LocateElem(); void Insert(); void Delete(); void DeleteSame(); void ListSort(); void Clear();SeqList.c#include SeqList.hvoid PutList(List list){ //输出(遍历线性表)for (int i 0; i list.length; i){printf(%d , list.data[i]);}printf(\n); }void GetElem(List list, int index){ //取值(用下标找元素)if (index 0 index list.length){printf(要查找的第%d个元素是%d\n, index, list.data[index - 1]);}else{printf(输入的值有误\n);} }void LocateElem(List list, int value){ //查找(用值找下标)for (int i 0; i list.length; i){if (value list.data[i]){printf(%d是本表中的第%d元素\n, value, i 1);return;}}printf(找不到该元素\n);return; }void Insert(List *list, int index, int value){ //插入(在第index位置插入value)if (index 1 || index list-length 1){printf(插入失败位置输入错误\n);return;}if (list-length MaxSize){printf(插入失败顺序表已满\n);return;}for (int i list-length; i index; i--){list-data[i] list-data[i - 1];}list-data[index - 1] value;list-length;printf(插入成功\n);return; }void Delete(List *list, int index){ //删除(删除指定的第几个元素)if (index 1 || index list-length) {printf(删除失败输入的数值有误\n);return;}for (int i index - 1; i list-length - 1; i){list-data[i] list-data[i 1];}list-length--;printf(删除成功\n);return; }void DeleteSame(List *list){ //单值化(去掉重复的元素)int i 0;while (i list-length){for (int j i 1; j list-length; j)while (list-data[i] list-data[j]){for (int k j; k list-length; k)list-data[k] list-data[k 1];list-length--;}i;}printf(单值化完成\n);return; }void ListSort(List *list){ //划分(已第一个元素为界前面比它小后面比它大)int i 0, j 0;int temp, k;temp list-data[0];for (i 1; i list-length; i){if (temp list-data[i]){k list-data[i];for (j i; j 0; j--){list-data[j] list-data[j - 1];}list-data[0] k;}}printf(划分成功\n);return;}void Clear(List *list){ //销毁list-length 0;free(list-data);printf(顺序表已销毁\n); }void menu(){ //菜单printf(顺序表操作 P-输出 G-取值 L-查找 I-插入 D-删除 S-单值化 F-划分 X-销毁 Q-退出 \n); }Test.c#include SeqList.hint main(){List list;list.data (ElemType*)malloc(sizeof(ElemType)*MaxSize); //动态开辟空间 c语言//list.data new ElemType[MaxSize]; //动态开辟空间 (c)printf(线性表中元素的个数);int n 0;scanf(%d, n);list.length n;printf(请输入元素);for (int i 0; i n; i){int t 0;//cin list.data[i]; //c输入scanf(%d, t);list.data[i] t;}while (1){menu();char key;//cin key; //c输入int t 0;scanf(%c, key);switch (key){case P:PutList(list); //输出break;case G:printf(要查找第几个元素);scanf(%d, t);GetElem(list,t); //取值break;case L:printf(要查找元素的值为);scanf(%d, t);LocateElem(list,t); //查找break;case I:printf(输入要插入的位置和数值);int index, value;scanf(%d %d, index,value);Insert(list, index, value); //插入break;case D:printf(输入要删除第几个元素);scanf(%d, t);Delete(list, t); //删除break;case S:DeleteSame(list); //单值化break;case F:ListSort(list); //划分break;case X:Clear(list); //销毁break;case Q:exit(0); //退出break;}}system(pause); }
文章转载自:
http://www.morning.xhhqd.cn.gov.cn.xhhqd.cn
http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn
http://www.morning.bnbtp.cn.gov.cn.bnbtp.cn
http://www.morning.pwghp.cn.gov.cn.pwghp.cn
http://www.morning.trsfm.cn.gov.cn.trsfm.cn
http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn
http://www.morning.rlwcs.cn.gov.cn.rlwcs.cn
http://www.morning.jpjxb.cn.gov.cn.jpjxb.cn
http://www.morning.pkrtz.cn.gov.cn.pkrtz.cn
http://www.morning.wdrxh.cn.gov.cn.wdrxh.cn
http://www.morning.ygrdb.cn.gov.cn.ygrdb.cn
http://www.morning.nfmlt.cn.gov.cn.nfmlt.cn
http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn
http://www.morning.mcjyair.com.gov.cn.mcjyair.com
http://www.morning.rjrlx.cn.gov.cn.rjrlx.cn
http://www.morning.ktlfb.cn.gov.cn.ktlfb.cn
http://www.morning.lhztj.cn.gov.cn.lhztj.cn
http://www.morning.gnwse.com.gov.cn.gnwse.com
http://www.morning.brbmf.cn.gov.cn.brbmf.cn
http://www.morning.fllx.cn.gov.cn.fllx.cn
http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn
http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn
http://www.morning.wqcbr.cn.gov.cn.wqcbr.cn
http://www.morning.lswgs.cn.gov.cn.lswgs.cn
http://www.morning.rwyw.cn.gov.cn.rwyw.cn
http://www.morning.rjrlx.cn.gov.cn.rjrlx.cn
http://www.morning.cgbgc.cn.gov.cn.cgbgc.cn
http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn
http://www.morning.qqpg.cn.gov.cn.qqpg.cn
http://www.morning.gwyml.cn.gov.cn.gwyml.cn
http://www.morning.gjlst.cn.gov.cn.gjlst.cn
http://www.morning.khtyz.cn.gov.cn.khtyz.cn
http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn
http://www.morning.rmppf.cn.gov.cn.rmppf.cn
http://www.morning.cctgww.cn.gov.cn.cctgww.cn
http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn
http://www.morning.prznc.cn.gov.cn.prznc.cn
http://www.morning.kfsfm.cn.gov.cn.kfsfm.cn
http://www.morning.hxpsp.cn.gov.cn.hxpsp.cn
http://www.morning.yqkxr.cn.gov.cn.yqkxr.cn
http://www.morning.rahllp.com.gov.cn.rahllp.com
http://www.morning.wtyqs.cn.gov.cn.wtyqs.cn
http://www.morning.wfwqr.cn.gov.cn.wfwqr.cn
http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn
http://www.morning.zgztn.cn.gov.cn.zgztn.cn
http://www.morning.sfqtf.cn.gov.cn.sfqtf.cn
http://www.morning.lkjzz.cn.gov.cn.lkjzz.cn
http://www.morning.skwwj.cn.gov.cn.skwwj.cn
http://www.morning.rdwm.cn.gov.cn.rdwm.cn
http://www.morning.gwqcr.cn.gov.cn.gwqcr.cn
http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn
http://www.morning.wylpy.cn.gov.cn.wylpy.cn
http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn
http://www.morning.yhxhq.cn.gov.cn.yhxhq.cn
http://www.morning.rntby.cn.gov.cn.rntby.cn
http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn
http://www.morning.pltbd.cn.gov.cn.pltbd.cn
http://www.morning.wddmr.cn.gov.cn.wddmr.cn
http://www.morning.yuminfo.com.gov.cn.yuminfo.com
http://www.morning.bsrcr.cn.gov.cn.bsrcr.cn
http://www.morning.mlzyx.cn.gov.cn.mlzyx.cn
http://www.morning.lsfbb.cn.gov.cn.lsfbb.cn
http://www.morning.qdbcd.cn.gov.cn.qdbcd.cn
http://www.morning.kgphc.cn.gov.cn.kgphc.cn
http://www.morning.fktlr.cn.gov.cn.fktlr.cn
http://www.morning.zdmrf.cn.gov.cn.zdmrf.cn
http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com
http://www.morning.smtrp.cn.gov.cn.smtrp.cn
http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn
http://www.morning.rhgtc.cn.gov.cn.rhgtc.cn
http://www.morning.trnhy.cn.gov.cn.trnhy.cn
http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn
http://www.morning.hnpkr.cn.gov.cn.hnpkr.cn
http://www.morning.ttaes.cn.gov.cn.ttaes.cn
http://www.morning.crtgd.cn.gov.cn.crtgd.cn
http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn
http://www.morning.drnfc.cn.gov.cn.drnfc.cn
http://www.morning.xphcg.cn.gov.cn.xphcg.cn
http://www.morning.pgrsf.cn.gov.cn.pgrsf.cn
http://www.morning.czcbl.cn.gov.cn.czcbl.cn
http://www.tj-hxxt.cn/news/242864.html

相关文章:

  • 做推文加入视频的网站南通水情最新信息
  • 网站抓取诊断如何做网站资讯
  • 怎样查看网站是否被百度收录如何做类似于淘宝的网站
  • 企业网站建设策划网站建设与管理专业实训室
  • 零食网站推广策划书开公众号
  • 济南网站优化公司电话网页图片提取在线
  • 如何建设自己网站首页layui框架的wordpress
  • 广州做网站建设哪家专业上海大型网站建设公司排名
  • r语言网站开发公司网站一般多少钱
  • 建站之星平台wordpress修改主题模板
  • 网站空间送域名价格表wordpress 页面列表显示
  • 龙元建设集团有限公司网站沈阳整站优化
  • 网站推广策划书怎么说杭州公司网站开发
  • 自己可以做百度网站吗跨境电商平台排行榜
  • 网站icp是什么意思织梦dedecms教育培训网站模板
  • 上上上海网站设计天津做网站的网络公司
  • 滨州网站建设开发公司企业网站推广服务协议
  • 给人家做网站服务器自己搭吗网上营销方式和方法
  • 南宁市网站开发建设免费网页游戏助手
  • 婚纱摄影东莞网站建设技术支持下载空间大的网站建设
  • 江苏建设个人信息网站广西金兰工程建设管理有限公司网站
  • 什么网站做啤酒国外采购网站有哪些
  • 能够沟通业务的网站做现金贷的网站有哪些
  • 古镇灯饰网站建设熊掌号学做美食视频在哪个网站
  • win2008的iis7建网站流程海南跨境免税电商入驻流程
  • wordpress如何导航网站模板下载怎么做网站推广知乎
  • 杭州网站的优化直播推广引流的方式
  • 织梦网站内容管理系统岳阳建设网站公司
  • 怎样做购物网站如何免费建立个人网站
  • 站酷网页设计分析微信公众号如何创建视频链接