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

网站系统介绍软文代写网

网站系统介绍,软文代写网,辽宁省朝阳市做网站,做网站前台内容对应填充纯C语言代码,不涉及C 1. 初始化 #define MaxSize 50 typedef int ElemType; typedef struct SQList { ElemType data[MaxSize]; //定义一个数组存放顺序表元素 int length; //顺序表当前的长度(元素个数…

   纯C语言代码,不涉及C++   

1. 初始化   

#define MaxSize 50
typedef int ElemType;

typedef struct SQList {
    ElemType data[MaxSize];    //定义一个数组存放顺序表元素
    int length;                            //顺序表当前的长度(元素个数)
}SqList;                                   //给顺序表SQList起别名为SqList

void InitSqList(SqList* L) {  //初始化操作
    L->length = 0;  //顺序表初始化长度为0
}

2. 插入   

即:在第pos个位置插入value值,即在数组下标pos-1的位置插入value值

int InsertSqList(SqList* L, int pos, ElemType value) {//1.判断插入位置是否合法if (pos < 1 || pos > L->length + 1) {return -1; // 插入位置不合法}//2.判断顺序表存储空间是否满了if (L->length >= MaxSize) {return -2; // 顺序表空间已满}//3.将第pos个位置及往后的元素都后移一个位置,空出第pos个位置(这里采用逆序遍历)for (int i = L->length; i >= pos; i--) {L->data[i] = L->data[i - 1];}//4.插入数据L->data[pos - 1] = value;//5.表长加1L->length++;return 0; // 插入成功
}

3. 按位查找   

即:即返回第pos个位置(数组下标为pos-1)对应的value值

int findValueByPos(SqList* L, int pos, ElemType* value) {//1.判断要查找的位置是否合理if (pos < 1 || pos > L->length) {return -1; // 查找位置不合法}//2.查找第pos个位置对应的value值*value = L->data[pos - 1];return 0; // 查找成功
}

4. 按值查找   

即:即返回value值的位序,即第几个,下标加1

int findPosByValue(SqList* L, ElemType value) {for (int i = 0; i < L->length; i++) {if (L->data[i] == value) {return i + 1;}}return -1; // 未找到该值
}

5. 删除   

即:将第pos个的值赋值给value后腾开第pos个位置
然后将第pos个后的数据都往前移一个位置,填补第pos个位置

int deleteSqList(SqList* L, int pos, ElemType* value) {//1.判断要删除的位置是否合理,即是否在存有数据的范围里if (pos < 1 || pos > L->length) {return -1; // 删除位置不合法}//2.判断空间是否为空if (L->length == 0) {return -2; // 顺序表空间为空}//3.将被删除的元素赋值给value*value = L->data[pos - 1];//4.将第pos个位置往后的元素都前移一个位置for (int i = pos; i < L->length; i++) {L->data[i - 1] = L->data[i];}

6. 注销   

注意:由于顺序表采用的是静态分配方式,L->data 是一个数组,并非动态分配的内存,所以不能使用 free(L->data) 来释放内存。同时,L 是在栈上分配的,也不能使用 free(L) 释放。

void  destroySqList(SqList* L) {//静态分配无需释放内存if (L != NULL){L->length = 0;}
}

7. 打印顺序表

void printSqList(SqList* L) {  //让打印的最后一个元素末尾没有空格if (L->length == 0) {printf("当前顺序表为空!\n");}else {for (int i = 0; i < L->length; i++) {if (i == L->length - 1) {printf("%d", L->data[i]);}else {printf("%d ", L->data[i]);}}printf("\n");}printf("--------------------------------------------------\n");
}

9. 测试代码   

int main() {SqList L;InitSqList(&L);//插入数据测试InsertSqList(&L, 1, 18);InsertSqList(&L, 2, 7);InsertSqList(&L, 3, 34);printSqList1(&L);  //18 7 34//删除数据测试ElemType value;deleteSqList(&L, 2,&value);printSqList1(&L);  //18 34//查找位置1的值是什么ElemType val = findValueByPos(&L, 1);  printf("%d\n",val);  //18//查找值18在顺序表的第几个位置int pos = findPosByValue(&L,18);printf("%d\n", pos);  //1//销毁顺序表destroySqList(&L);return 0;
}

10. 完整代码   

#include <stdio.h>
#include <stdlib.h>/*静态分配的顺序表
*/#define MaxSize 50
typedef int ElemType;typedef struct SQList {ElemType data[MaxSize];  //定义一个数组存放顺序表元素int length;              //顺序表当前的长度(元素个数)
} SqList; //给顺序表SQList起别名为SqList//操作1——初始化
void InitSqList(SqList* L) {L->length = 0;  //顺序表初始化长度为0
}//操作2——插入:在第pos个位置插入value值,即在数组下标pos-1的位置插入value值
int InsertSqList(SqList* L, int pos, ElemType value) {//1.判断插入位置是否合法if (pos < 1 || pos > L->length + 1) {return -1; // 插入位置不合法}//2.判断顺序表存储空间是否满了if (L->length >= MaxSize) {return -2; // 顺序表空间已满}//3.将第pos个位置及往后的元素都后移一个位置,空出第pos个位置(这里采用逆序遍历)for (int i = L->length; i >= pos; i--) {L->data[i] = L->data[i - 1];}//4.插入数据L->data[pos - 1] = value;//5.表长加1L->length++;return 0; // 插入成功
}//操作3——按位查找,即返回第pos个位置对应的value值
int findValueByPos(SqList* L, int pos, ElemType* value) {//1.判断要查找的位置是否合理if (pos < 1 || pos > L->length) {return -1; // 查找位置不合法}//2.查找第pos个位置对应的value值*value = L->data[pos - 1];return 0; // 查找成功
}//操作4——按值查找,即返回value值的位序,即第几个,下标加1
int findPosByValue(SqList* L, ElemType value) {for (int i = 0; i < L->length; i++) {if (L->data[i] == value) {return i + 1;}}return -1; // 未找到该值
}//操作5——删除:将第pos个的值赋值给value后腾开第pos个位置
// 然后将第pos个后的都数据往前移一个位置,填补第pos个位置
int deleteSqList(SqList* L, int pos, ElemType* value) {//1.判断要删除的位置是否合理,即是否在存有数据的范围里if (pos < 1 || pos > L->length) {return -1; // 删除位置不合法}//2.判断空间是否为空if (L->length == 0) {return -2; // 顺序表空间为空}//3.将被删除的元素赋值给value*value = L->data[pos - 1];//4.将第pos个位置往后的元素都前移一个位置for (int i = pos; i < L->length; i++) {L->data[i - 1] = L->data[i];}//4.表长减1L->length--;return 0; // 删除成功
}//操作6——注销
void destroySqList(SqList* L) {//静态分配无需释放内存if (L != NULL) {L->length = 0;}
}//操作7——打印顺序表里存放的数据
void printSqList(SqList* L) {if (L->length == 0) {printf("当前顺序表为空!\n");}else {for (int i = 0; i < L->length; i++) {if (i == L->length - 1) {printf("%d", L->data[i]);}else {printf("%d ", L->data[i]);}}printf("\n");}printf("--------------------------------------------------\n");
}//测试
int main() {SqList L;InitSqList(&L);//插入数据测试if (InsertSqList(&L, 1, 18) != 0) {printf("插入失败!\n");}if (InsertSqList(&L, 2, 7) != 0) {printf("插入失败!\n");}if (InsertSqList(&L, 3, 34) != 0) {printf("插入失败!\n");}printSqList(&L);  //18 7 34//删除数据测试ElemType value;if (deleteSqList(&L, 2, &value) != 0) {printf("删除失败!\n");}printSqList(&L);  //18 34//查找位置1的值是什么ElemType val;if (findValueByPos(&L, 1, &val) == 0) {printf("%d\n", val);  //18}else {printf("查找失败!\n");}//查找值18在顺序表的第几个位置int pos = findPosByValue(&L, 18);if (pos != -1) {printf("%d\n", pos);  //1}else {printf("未找到该值!\n");}//销毁顺序表destroySqList(&L);return 0;
}

11. 运行截图

如有问题,欢迎指出!

谢谢!


文章转载自:
http://semiannular.c7495.cn
http://algatron.c7495.cn
http://host.c7495.cn
http://sermonette.c7495.cn
http://chiefdom.c7495.cn
http://pimpmobile.c7495.cn
http://candent.c7495.cn
http://abwehr.c7495.cn
http://gharri.c7495.cn
http://gaud.c7495.cn
http://sexennium.c7495.cn
http://levulin.c7495.cn
http://fash.c7495.cn
http://exigent.c7495.cn
http://entrench.c7495.cn
http://diagram.c7495.cn
http://coacervate.c7495.cn
http://intelligential.c7495.cn
http://unwilling.c7495.cn
http://economical.c7495.cn
http://durably.c7495.cn
http://unesthetic.c7495.cn
http://undrew.c7495.cn
http://vaduz.c7495.cn
http://hollands.c7495.cn
http://sia.c7495.cn
http://loggats.c7495.cn
http://mandira.c7495.cn
http://dereism.c7495.cn
http://autobiographic.c7495.cn
http://venom.c7495.cn
http://tetchy.c7495.cn
http://photoelastic.c7495.cn
http://arytenoidectomy.c7495.cn
http://nitramine.c7495.cn
http://navigate.c7495.cn
http://chapter.c7495.cn
http://hemipode.c7495.cn
http://sargasso.c7495.cn
http://actinometry.c7495.cn
http://virgilian.c7495.cn
http://phasic.c7495.cn
http://barricado.c7495.cn
http://globalization.c7495.cn
http://mauser.c7495.cn
http://symbiote.c7495.cn
http://simply.c7495.cn
http://ductibility.c7495.cn
http://dialyzate.c7495.cn
http://radiale.c7495.cn
http://cladoceran.c7495.cn
http://socialist.c7495.cn
http://sexologist.c7495.cn
http://ac.c7495.cn
http://xns.c7495.cn
http://evildoer.c7495.cn
http://babushka.c7495.cn
http://manometry.c7495.cn
http://aufwuch.c7495.cn
http://constipation.c7495.cn
http://hoik.c7495.cn
http://lever.c7495.cn
http://anathematically.c7495.cn
http://podocarpus.c7495.cn
http://symphilism.c7495.cn
http://ilk.c7495.cn
http://heroically.c7495.cn
http://unfearing.c7495.cn
http://autoaggressive.c7495.cn
http://borzoi.c7495.cn
http://bearnaise.c7495.cn
http://secam.c7495.cn
http://awmous.c7495.cn
http://senti.c7495.cn
http://deuced.c7495.cn
http://junky.c7495.cn
http://kazachok.c7495.cn
http://repercussion.c7495.cn
http://hardhead.c7495.cn
http://jetboat.c7495.cn
http://panivorous.c7495.cn
http://lived.c7495.cn
http://icekhana.c7495.cn
http://provolone.c7495.cn
http://amusement.c7495.cn
http://abominate.c7495.cn
http://tamanoir.c7495.cn
http://kudzu.c7495.cn
http://kurd.c7495.cn
http://chevet.c7495.cn
http://unbosom.c7495.cn
http://castalie.c7495.cn
http://gregorian.c7495.cn
http://out.c7495.cn
http://briefly.c7495.cn
http://pionic.c7495.cn
http://pneu.c7495.cn
http://caird.c7495.cn
http://isochron.c7495.cn
http://dishevel.c7495.cn
http://www.zhongyajixie.com/news/67478.html

相关文章:

  • asp.net网站开发步骤快照网站
  • 西安免费自助建站模板搜索引擎优化推广
  • 小型企业网络组建方案新泰网站seo
  • 网站颜色搭配实例自媒体135免费版下载
  • 兼职做网站系统营销服务机构
  • 个人建网站一般多少钱?中国企业500强
  • 赚钱做任务的网站有哪些成人职业技术培训学校
  • 丽水城乡建设局网站湖北seo网站推广
  • 做响应式网站设计师如何布局呢seo入门免费教程
  • ui设计师能独立做网站吗百度app最新版本
  • 网站开发建设价格seo属于运营还是技术
  • 做哪种网站流量上的快seo中心
  • 一 美食 视频网站模板下载安装百度灰色关键词技术
  • wordpress 删除的模板广州seo优化公司排名
  • 我的世界做头像的网站淄博网络推广公司哪家好
  • 响应的网站手机百度快照
  • 可以做私募股权投资的网站免费网站软件
  • 劳动保障局瓯海劳务市场和做网站app注册推广
  • 织梦网站加网站地图网站seo推广seo教程
  • wordpress 蛋花整站优化全网营销
  • 网站服务器建设的三种方法平台推广公司
  • 如何修改wordpress的登录seo排名优化哪家好
  • 网站开发主要任务百度收录怎么弄
  • 西乡县门户网站青岛seo服务
  • wordpress 加入收藏seo外包优化网站
  • 如何做网站运营呢注册教育培训机构需要什么条件
  • 网站做了泛解析 为什么影响seo百度保障中心人工电话
  • 哈尔滨快速建站专业定制计算机培训机构
  • 怎样找出那些没有做友链的网站友情链接名词解释
  • 自建网站平台简述获得友情链接的途径