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

网站建设昆明包装设计优化网络的软件

网站建设昆明包装设计,优化网络的软件,经典的响应式布局网站,查企企官方网站目录 前言 顺序表实现 01-开发环境 02-文件布局 03-代码 01-主函数 02-头文件 03-SeqListCommon.cpp 04-SeqListPositionOperation.cpp 05-SeqListValueOperation.cpp 结语 前言 此专栏包含408考研数据结构全部内容,除其中使用到C引用外,全为…

目录

前言

顺序表实现

01-开发环境

02-文件布局

03-代码

01-主函数

02-头文件

03-SeqListCommon.cpp

04-SeqListPositionOperation.cpp

05-SeqListValueOperation.cpp

结语

前言

        此专栏包含408考研数据结构全部内容,除其中使用到C++引用外,全为C语言代码。使用C++引用主要是为了简化指针的使用,避免二重指针的出现。

顺序表实现

01-开发环境

        语言:C/C++14

        编译器:MinGW64

        集成开发环境:CLion2022.1.3

02-文件布局

        请在CLion集成开发环境中创建C++可执行程序,否则无法运行,原因上面已解释。

                        

03-代码

01-主函数

        用于测试和初始化顺序表。

#include "./Head/SeqListData.h"
#include "./Source/SeqListCommon.cpp"
#include "./Source/SeqListPositionOperation.cpp"
#include "./Source/SeqListValueOperation.cpp"int main() {// 定义与初始化SeqList List;List.data[0] = 1;List.data[1] = 2;List.data[2] = 3;List.data[3] = 4;List.data[4] = 2;List.data[5] = 3;List.length = 6;// 位置操作// 插入int position = 1, value = 60;SeqListInsertPosition(List, position, value);SeqListPrint(List);printf("----------------------\n");// 删除
//    position = 1;
//    SeqListDeletePosition(List, position);
//    SeqListPrint(List);
//    printf("----------------------\n");// 修改
//    position = 2;
//    value = 20;
//    SeqListModifyPosition(List, position, value);
//    SeqListPrint(List);// 查找
//    position = 1;
//    SeqListSearchPosition(List, position, value);
//    printf("%d at position %d", value, position);// 内容操作SeqListPrint(List);printf("----------------------\n");// 删除
//    int value = 2, position = 0;
//    SeqListDeleteAllContent(List, value);
//    SeqListPrint(List);// 查找
//    value = 3;
//    position = 0;
//    SeqListSearchContent(List, value, position);
//    SeqListPrint(List);//    value = 3;
//    int positionList[MAXSIZE];
//    SeqListSearchAllContent(List, value, positionList);
//    SeqListPrint(List);// 修改
//    int sourceValue = 2, modifyValue = 20;
//    SeqListModifyAllContent(List, sourceValue, modifyValue);
//    SeqListPrint(List);
//    SeqListInsertAllContent(List, 2, 20);
//    SeqListPrint(List);
//    printf("%d\n", List.length);return 0;
}

02-头文件

        用于存储结构体和常量等。

//
// Created by 24955 on 2023-02-19.
//#ifndef SEQLIST_SEQLISTDATA_H
#define SEQLIST_SEQLISTDATA_H
// 头文件
#include <stdio.h>// 常量
#define MAXSIZE 50
#define ElemType int// SeqList结构体定义
typedef struct {ElemType data[MAXSIZE];int length;
} SeqList;
#endif //SEQLIST_SEQLISTDATA_H

03-SeqListCommon.cpp

        用于存储公共函数。

//
// Created by 24955 on 2023-02-19.
//
void SeqListPrint(SeqList List) {for (int i = 0; i < List.length; i++) {printf("%3d", List.data[i]);}printf("\n");
}

04-SeqListPositionOperation.cpp

        用于存储按位置操作的函数。

//
// Created by 24955 on 2023-02-19.
//
// 插入操作
void SeqListInsertPosition(SeqList &List, int position, ElemType value) {/** 1. 判断插入位置是否合法,数组是否已满* 2. 后移数据* 3. 插入,长度+1*/if (position >= 1 && position <= List.length + 1 && List.length != MAXSIZE) {for (int i = List.length; i >= position; i--) {List.data[i] = List.data[i - 1];}List.data[position - 1] = value;List.length++;printf("Insert Success.\n");} else {printf("Illegal input, please re-enter.\n");}
}// 删除操作
void SeqListDeletePosition(SeqList &List, int position) {/** 1. 判断删除位置是否合法* 2. 移动数据*/if (position >= 1 && position <= List.length) {for (int i = position; i < List.length; i++) {List.data[i - 1] = List.data[i];}List.length--;printf("Delete Success.\n");} else {printf("Illegal input, please re-enter.\n");}
}// 修改操作
void SeqListModifyPosition(SeqList &List, int position, ElemType value) {/** 1. 判断修改位置是否合法* 2. 修改数据*/if (position >= 1 && position <= List.length) {List.data[position - 1] = value;printf("Modify Success.\n");} else {printf("Illegal input, please re-enter.\n");}
}// 查找操作
void SeqListSearchPosition(SeqList List, int position, ElemType &value) {if (position >= 1 && position <= List.length) {value = List.data[position - 1];printf("Search Success.\n");} else {printf("Illegal input, please re-enter.\n");}
}

05-SeqListValueOperation.cpp

        用于存储按值操作的函数。

//
// Created by 24955 on 2023-02-19.
//
// 在第一个匹配元素位置处插入一个元素
void SeqListInsertContent(SeqList &List, ElemType value, ElemType insertValue) {/** 1. 匹配内容所在位置* 2. 调用SeqListInsertPosition函数插入数据*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {SeqListInsertPosition(List, i + 1, insertValue);ret = false;break;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {printf("Insert %d success.\n", insertValue);}
}// 在全部匹配元素位置处插入一个元素
void SeqListInsertAllContent(SeqList &List, ElemType value, ElemType insertValue) {/** 1. 匹配内容所在位置* 2. 调用SeqListInsertPosition函数插入数据并将i+1* 3. 插入后匹配内容后移,因此需i+1跳过上次匹配值*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {SeqListInsertPosition(List, i + 1, insertValue);i++;ret = false;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {printf("Insert %d success.\n", insertValue);}
}// 删除第一个匹配元素
void SeqListDeleteContent(SeqList &List, ElemType value) {/** 1. 匹配删除位置* 2. 调用SeqListDeletePosition函数删除数据并中断循环*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {SeqListDeletePosition(List, i + 1);ret = false;break;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {printf("Delete %d success.\n", value);}
}// 删除全部匹配元素
void SeqListDeleteAllContent(SeqList &List, ElemType value) {/** 1. 匹配删除位置* 2. 调用SeqListDeletePosition函数删除数据*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {SeqListDeletePosition(List, i + 1);ret = false;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {printf("Delete %d success.\n", value);}
}// 修改第一个匹配内容
void SeqListModifyContent(SeqList &List, ElemType sourceValue, ElemType modifyValue) {/** 1. 匹配修改元素位置* 2. 修改元素*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == sourceValue) {List.data[i] = modifyValue;ret = false;break;}}if (ret) {printf("Don't find %d, please re-enter.\n", sourceValue);} else {printf("Modify Success.\n");}
}// 修改所有匹配内容
void SeqListModifyAllContent(SeqList &List, ElemType sourceValue, ElemType modifyValue) {/** 1. 匹配修改元素位置* 2. 修改元素*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == sourceValue) {List.data[i] = modifyValue;ret = false;}}if (ret) {printf("Don't find %d, please re-enter.\n", sourceValue);} else {printf("Modify Success.\n");}
}// 查找第一个匹配元素,并返回其所在位置
void SeqListSearchContent(SeqList List, ElemType value, int &position) {/** 1. 匹配查找内容* 2. 返回内容所在位置*/bool ret = true;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {position = i + 1;ret = false;break;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {printf("Search Success, %d at position %d.\n", value, position);}
}// 查找全部匹配元素,并返回其所在位置
void SeqListSearchAllContent(SeqList List, ElemType value, int position[MAXSIZE]) {/** 1. 匹配查找内容* 2. 返回所有匹配位置,用数组接收*/bool ret = true;int index = 0;for (int i = 0; i < List.length; i++) {if (List.data[i] == value) {position[index] = i + 1;index++;ret = false;}}if (ret) {printf("Don't find %d, please re-enter.\n", value);} else {for (int j = 0; j < index; j++) {printf("Search Success, %d at position %d.\n", value, position[j]);}}
}

结语

        此博客主要用于408考研数据结构C语言实现记录,内有不足,可留言,可讨论。

http://www.mnyf.cn/news/41680.html

相关文章:

  • 黄山市非遗网站策划书友情链接互换网站
  • 做一个企业的网站怎么做企点客服
  • 自己的ip做网站seo技术培训东莞
  • unity网站后台怎么做免费个人网站源码
  • wordpress怎么修改主题首页网站建设seo
  • 美图秀秀网页版在线使用人员优化方案
  • 做网站图片太大好吗公司品牌宣传方案
  • 做微课的网站有哪些如何建立网页
  • 大型网站开发自动推广软件免费
  • 我的网站域名aso安卓优化公司
  • 美容行业培训网站建设网络媒体软文案例
  • 郑州网站开发公网站托管
  • 建设部网站建造师管理号营销策略都有哪些
  • 做响应式网站有什么插件seo扣费系统
  • 网站建设公司58郑州网络公司
  • 网站开发建设成本抖音seo排名优化
  • 深圳市网站建设清远头条新闻
  • 合肥网站搭建网站快速有排名
  • 网站留言板块怎么做建立网站一般要多少钱
  • 绍兴网站建设公司电话网络营销的优化和推广方式
  • 江门网站制作方案定制微信小程序开发教程
  • 网站一般的后台成人用品推广网页
  • 怎样在百度做网站宁波seo关键词优化制作
  • 网站推广对接引擎搜索大全
  • 网站打开速度优化优化设计答案五年级下册
  • 怎么搭建钓鱼网站北京专业seo公司
  • 连云港营销型网站建设ebay欧洲站网址
  • h5响应式网站建设软文代理平台
  • 做企业网站 asp的cms系统哪个好win10一键优化工具
  • 诊断网站seo现状的方法百度信息流代运营