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

怎么建立小公司网站网页设计实训总结意义报告

怎么建立小公司网站,网页设计实训总结意义报告,鱼巴士设计师服务平台,品牌推广的三个阶段无头单向非循环链表的建立 前言——什么链表链表形象图链表分类 一、Single_linked_list.h头文件的建立二、Single_linked_list.c功能函数的定义Single_linked_list_test.c主函数的定义四、代码运行测试五、Single_linked_list完整代码演示#xff1a;总结 前言——什么链表 链… 无头单向非循环链表的建立 前言——什么链表链表形象图链表分类 一、Single_linked_list.h头文件的建立二、Single_linked_list.c功能函数的定义Single_linked_list_test.c主函数的定义四、代码运行测试五、Single_linked_list完整代码演示总结 前言——什么链表 链表的概念及结构概念 链表是一种物理存储结构上非连续、非顺序的存储结构数据元素的逻辑顺序是通过链表中的指针链接次序实现的 。 链表形象图 链表具体表现是怎么样的呢让我们通过下面的图片来了解一下 形象一点形容呢那就像一个车厢相互链接的火车这样好记住多了吧 注意 . 从上图可看出链式结构在逻辑上是连续的但在物理上不一定连续 . 现实中的结点一般是都是从堆上申请来的 . 从堆上申请的空间是按照一定的策略来分配的两次申请的空间可能连续也可能不连续 链表分类 实际中链表的结构非常多样以下情况组合起来就有8种链表结构 单向或者双向 带头或者不带头 循环或者非循环 虽然有这么多的链表的结构但是我们实际中最常用还是两种结构 无头单向非循环链表 带头双向循环链表 今天我们要实现的是无头单向非循环链表让我们跟随下面的步骤来建立单链表吧 一、Single_linked_list.h头文件的建立 1.头文件的声明 #pragma once #includestdio.h #includestdlib.h #includeassert.h2.单链表的接口实现 typedef int SLTDataType;//类型重命名 //单链表接口定义 typedef struct SListNode {SLTDataType data;struct SListNode* next; }SLTNode;3.打印函数以及创建结点函数的声明 //打印 void SLTPrint(SLTNode* phead); //创建结点 SLTNode* BuySListNode(SLTDataType x);4.尾插、头插函数的声明 //尾插 void SLTPushBack(SLTNode** pphead, SLTDataType x); //头插 void SLTPushFront(SLTNode** pphead, SLTDataType x);5.尾删头删函数的声明 //尾删 void SLTPopBack(SLTNode** pphead); //头删 void SLTPopFront(SLTNode** pphead);6.查找函数的声明 SLTNode* SLTFind(SLTNode* phead, SLTDataType x);7.定点pos前后插入函数的声明 // 在pos之前插入x void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x); // 在pos以后插入x void SLTInsertAfter(SLTNode** pphead,SLTNode* pos, SLTDataType x);8.定点删除pos或删除pos后一位结点的函数的声明 // 删除pos位置 void SLTErase(SLTNode** pphead, SLTNode* pos); // 删除pos的后一个位置 void SLTEraseAfter(SLTNode** pphead, SLTNode* pos);二、Single_linked_list.c功能函数的定义 1.头文件的声明 #include Single_linked_list.h2.打印函数以及创建结点函数的定义 //打印 void SLTPrint(SLTNode* phead) {SLTNode* cur phead;while (cur)//cur!NULL为真{printf(%d , cur-data);cur cur-next;}printf(NULL\n);//打印尾结点的next结点NULL }//创建结点 SLTNode* BuySListNode(SLTDataType x) {SLTNode* newnode (SLTNode*)malloc(sizeof(SLTNode));//创建一个新结点if (newnode NULL)//创建失败返回错误结束程序{perror(malloc fail);exit(-1);}newnode-data x;newnode-next NULL;//将新结点的next结点置为NULLreturn newnode; }3.尾插、头插函数的定义 //尾插 //传入结构体指针用二级指针接收 void SLTPushBack(SLTNode** pphead, SLTDataType x) {SLTNode* newnode BuySListNode(x);//调用函数创建新结点//两种情况 头结点为空时和头结点不为空时if (*pphead NULL){// 改变的结构体的指针所以要用二级指针*pphead newnode;}else{SLTNode* tail *pphead;while (tail-next ! NULL)//遍历链表到尾结点{tail tail-next;}// 改变的结构体用结构体的指针即可tail-next newnode;} }//头插 void SLTPushFront(SLTNode** pphead, SLTDataType x) {SLTNode* newnode BuySListNode(x);newnode-next *pphead;// 改变的结构体的指针所以要用二级指针*pphead newnode; }4.尾删头删函数的定义 //尾删 void SLTPopBack(SLTNode** pphead) {assert(*pphead);//判断*pphead是否为空//一个节点if ((*pphead)-next NULL){free(*pphead);*pphead NULL;}else//一个以上节点{SLTNode* tail *pphead;while (tail-next-next)//遍历链表到尾结点{tail tail-next;}free(tail-next);tail-next NULL;} }//头删 void SLTPopFront(SLTNode** pphead) {assert(*pphead);//判断*pphead是否为空SLTNode* newhead (*pphead)-next;free(*pphead);*pphead newhead; }当然尾删不只一种方法另一种方法就是 void SLTPopBack(SLTNode** pphead) {assert(*pphead);if ((*pphead)-next NULL){free(*pphead);*pphead NULL;}else{SLTNode* tailPrev NULL;//设置一个前驱结点方便置空SLTNode* tail *pphead;while (tail-next){tailPrev tail;tail tail-next;}free(tail);tailPrev-next NULL;} }5.查找函数的定义 SLTNode* SLTFind(SLTNode* phead, SLTDataType x) {SLTNode* cur phead;while (cur ! NULLcur-data ! x ) {cur cur-next;}if (cur NULL) {printf(未查找到有效结点\n);exit(-1);}return cur; }6.定点pos前后插入函数的定义 // 在pos之前插入x void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x) {SLTNode* newnode BuySListNode(x);SLTNode* curPrev *pphead;SLTNode* cur SLTFind(curPrev,pos-data);if (curPrev cur) {newnode-next *pphead;*pphead newnode;}else {while (curPrev-next ! cur) {curPrev curPrev-next;}newnode-next cur;curPrev-next newnode;} }// 在pos以后插入x void SLTInsertAfter(SLTNode** pphead,SLTNode* pos, SLTDataType x) {SLTNode* newnode BuySListNode(x);SLTNode* temp *pphead;SLTNode* cur SLTFind(temp, pos-data);newnode-next cur-next;cur-next newnode; }7.定点删除pos或删除pos后一位结点的函数的定义 // 删除pos位置 void SLTErase(SLTNode** pphead, SLTNode* pos) {SLTNode* temp *pphead;SLTNode* curPrev *pphead;SLTNode* cur SLTFind(temp, pos-data);if (curPrev cur) {temp cur-next;free(cur);cur temp;}else {while (curPrev-next ! cur) {curPrev curPrev-next;}curPrev-next cur-next;free(cur);cur NULL;} }// 删除pos的后一个位置 void SLTEraseAfter(SLTNode** pphead, SLTNode* pos) {SLTNode* temp *pphead;SLTNode* cur SLTFind(temp, pos-data);if (cur-next NULL) {return;}else {temp cur-next;cur-next temp-next;free(temp);temp NULL;} }Single_linked_list_test.c主函数的定义 1.头文件的声明 #include Single_linked_list.h2.测试调用函数的定义 void TestSList() {SLTNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushBack(plist, 5);SLTPrint(plist);SLTPushFront(plist, 10);SLTPushFront(plist, 20);SLTPushFront(plist, 30);SLTPushFront(plist, 40);SLTPrint(plist);SLTNode* pos BuySListNode(3);SLTInsert(plist,pos, 6);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTInsertAfter(plist, pos, 7);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(6);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(7);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(1);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist); }3.主函数的定义 int main() {TestSList();return 0; }四、代码运行测试 示例一 void TestSList2() {SLTNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushBack(plist, 5);SLTPrint(plist);SLTPushFront(plist, 10);SLTPushFront(plist, 20);SLTPushFront(plist, 30);SLTPushFront(plist, 40);SLTPrint(plist); }运行结果 示例二 void TestSList3() {SLTNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushBack(plist, 5);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);}运行结果 示例三 void TestSList5() {SLTNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushBack(plist, 5);SLTPrint(plist);SLTNode* pos BuySListNode(3);SLTInsert(plist,pos, 6);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTInsertAfter(plist, pos, 7);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(6);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(7);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(1);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist); }运行结果 五、Single_linked_list完整代码演示 Single_linked_list.h #pragma once #includestdio.h #includestdlib.h #includeassert.htypedef int SLTDataType;//类型重命名 //单链表接口定义 typedef struct SListNode {SLTDataType data;struct SListNode* next; }SLTNode;//打印 void SLTPrint(SLTNode* phead); //创建结点 SLTNode* BuySListNode(SLTDataType x);//尾插 void SLTPushBack(SLTNode** pphead, SLTDataType x); //头插 void SLTPushFront(SLTNode** pphead, SLTDataType x);//尾删 void SLTPopBack(SLTNode** pphead); //头删 void SLTPopFront(SLTNode** pphead);//查找 SLTNode* SLTFind(SLTNode* phead, SLTDataType x);// 在pos之前插入x void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x);// 在pos以后插入x void SLTInsertAfter(SLTNode** pphead,SLTNode* pos, SLTDataType x);// 删除pos位置 void SLTErase(SLTNode** pphead, SLTNode* pos);// 删除pos的后一个位置 void SLTEraseAfter(SLTNode** pphead, SLTNode* pos);Single_linked_list.c #include Single_linked_list.h//打印 void SLTPrint(SLTNode* phead) {SLTNode* cur phead;while (cur)//cur!NULL为真{printf(%d , cur-data);cur cur-next;}printf(NULL\n);//打印尾结点的next结点NULL }//创建结点 SLTNode* BuySListNode(SLTDataType x) {SLTNode* newnode (SLTNode*)malloc(sizeof(SLTNode));//创建一个新结点if (newnode NULL)//创建失败返回错误结束程序{perror(malloc fail);exit(-1);}newnode-data x;newnode-next NULL;//将新结点的next结点置为NULLreturn newnode; }//尾插 //传入结构体指针用二级指针接收 void SLTPushBack(SLTNode** pphead, SLTDataType x) {SLTNode* newnode BuySListNode(x);//调用函数创建新结点//两种情况 头结点为空时和头结点不为空时if (*pphead NULL){// 改变的结构体的指针所以要用二级指针*pphead newnode;}else{SLTNode* tail *pphead;while (tail-next ! NULL)//遍历链表到尾结点{tail tail-next;}// 改变的结构体用结构体的指针即可tail-next newnode;} }//头插 void SLTPushFront(SLTNode** pphead, SLTDataType x) {SLTNode* newnode BuySListNode(x);newnode-next *pphead;// 改变的结构体的指针所以要用二级指针*pphead newnode; }//尾删 void SLTPopBack(SLTNode** pphead) {assert(*pphead);//判断*pphead是否为空//一个节点if ((*pphead)-next NULL){free(*pphead);*pphead NULL;}else//一个以上节点{SLTNode* tail *pphead;while (tail-next-next)//遍历链表到尾结点{tail tail-next;}free(tail-next);tail-next NULL;} }//头删 void SLTPopFront(SLTNode** pphead) {assert(*pphead);//判断*pphead是否为空SLTNode* newhead (*pphead)-next;free(*pphead);*pphead newhead; }//查找 SLTNode* SLTFind(SLTNode* phead, SLTDataType x) {SLTNode* cur phead;while (cur ! NULLcur-data ! x ) {cur cur-next;}if (cur NULL) {printf(未查找到有效结点\n);exit(-1);}return cur; }// 在pos之前插入x void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x) {SLTNode* newnode BuySListNode(x);SLTNode* curPrev *pphead;SLTNode* cur SLTFind(curPrev,pos-data);if (curPrev cur) {newnode-next *pphead;*pphead newnode;}else {while (curPrev-next ! cur) {curPrev curPrev-next;}newnode-next cur;curPrev-next newnode;} }// 在pos以后插入x void SLTInsertAfter(SLTNode** pphead,SLTNode* pos, SLTDataType x) {SLTNode* newnode BuySListNode(x);SLTNode* temp *pphead;SLTNode* cur SLTFind(temp, pos-data);newnode-next cur-next;cur-next newnode; }// 删除pos位置 void SLTErase(SLTNode** pphead, SLTNode* pos) {SLTNode* temp *pphead;SLTNode* curPrev *pphead;SLTNode* cur SLTFind(temp, pos-data);if (curPrev cur) {temp cur-next;free(cur);cur temp;}else {while (curPrev-next ! cur) {curPrev curPrev-next;}curPrev-next cur-next;free(cur);cur NULL;} }// 删除pos的后一个位置 void SLTEraseAfter(SLTNode** pphead, SLTNode* pos) {SLTNode* temp *pphead;SLTNode* cur SLTFind(temp, pos-data);if (cur-next NULL) {return;}else {temp cur-next;cur-next temp-next;free(temp);temp NULL;} }Single_linked_list_test.c void TestSList() {SLTNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushBack(plist, 5);SLTPrint(plist);SLTNode* pos BuySListNode(3);SLTInsert(plist,pos, 6);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTInsertAfter(plist, pos, 7);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(6);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(7);SLTErase(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(3);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist);pos BuySListNode(1);SLTEraseAfter(plist, pos);free(pos);pos NULL;SLTPrint(plist); }int main() {TestSList();return 0; }总结 无头单项非循环链表是链表的初始内容 有点难度但是不多记住指针与多级指针之间的关系 我相信大家也一定可以写出比我更好的代码
http://www.pierceye.com/news/367305/

相关文章:

  • wordpress 网站logowin系统没有wordpress
  • 玉山电商网站建设东莞市建设规划局网站
  • 网站建设运营公司企业特色c2c的代表性的电商平台
  • 上海网站建设,分类广告软件公司简介
  • 网站虚拟主机被国家禁止访问的网站怎么打开
  • wordpress手机加载不出来优化官网咨询
  • 平台网站建设预算表如何来做网站
  • 温州网站制作企业东莞网络推广公司电话
  • 网站建设的条件重庆那些网站
  • 伊犁网站制作大连甘井子区房价
  • 循环视频做网站背景win2012r2 建设网站
  • 建设网站制作汉狮团队义乌北苑编程网站开发公司
  • 网站开发公司会计处理滨州市住房和城乡建设局网站
  • 企业网站站内优化长尾关键词挖掘站长工具
  • 山东平台网站建设企业怎么做自己的品牌网站
  • 长沙seo网站排名杭州网站建设q479185700棒
  • 泰州网站建设搭建工程造价网
  • 网站流程优化c2c模式举例子
  • 帝国网站调用图片集网店平台有哪些
  • 做flash音乐网站的开题报告删除wordpress左上角
  • php网站开发学什么衡水大型网站建设
  • 广州网站开发软件平台wordpress 问号
  • 西安市建设干部学校网站厦门网站优化服务
  • 深圳市南山区住房和建设局官方网站如何把html网站改为asp网站
  • 网站建设有什么技术做dw网站图片怎么下载地址
  • 初中生如何做网站潍坊网站开发
  • 如何修改用织梦做的网站的模板价格对比网站开发
  • 单位建设网站的作用意义家在深圳坂田业主论坛
  • 网站什么时候备案好宜昌网站建设
  • 那个网站可以查询美做空基金竹中建设官方网站