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

辽宁省品牌建设促进会网站扬中零壹网站建设

辽宁省品牌建设促进会网站,扬中零壹网站建设,中国外贸网站有哪些问题,网站设计及内容策划CSDN主页#xff1a;醋溜马桶圈_C语言进阶,初始C语言,数据结构-CSDN博客 Gitee主页#xff1a;mnxcc (mnxcc) - Gitee.com 专栏#xff1a;数据结构_醋溜马桶圈的博客-CSDN博客 目录 1.认识单链表 2.创建单链表 3.单链表的操作 3.1打印单链表 3.2开辟新空间 3.3尾插 3.4头插… CSDN主页醋溜马桶圈_C语言进阶,初始C语言,数据结构-CSDN博客 Gitee主页mnxcc (mnxcc) - Gitee.com 专栏数据结构_醋溜马桶圈的博客-CSDN博客 目录 1.认识单链表 2.创建单链表 3.单链表的操作 3.1打印单链表 3.2开辟新空间 3.3尾插 3.4头插 3.5尾删 3.6头删 3.7查找 3.8在pos前面插入 3.9删除pos位置 3.10销毁 3.11在pos位置之后插入  3.12删除pos位置之后的值 4.总代码 SList.h SList.c test.c 我们之前学习了顺序表的有关知识顺序表存在下面的问题 尾插效率还不错头插或中间插入删除需要挪动数据效率低满了以后只能扩容扩容是有一定的消耗的扩容一般存在一定的空间浪费 1.认识单链表 这篇文章我们来认识一下单链表 如果想要插入一个结点就不需要挪动数据了改指针的指向就可以了 同样我们删除结点直接将前一个结点的指针指向后一个结点就可以了 首先我们还是从工程的角度去考虑创建SList.h SList.c test.c三个文件 SList.h放置函数的声明 SList.c放置函数的定义 test.c进行测试  2.创建单链表 3.单链表的操作 3.1打印单链表 //打印单链表 //尽量不要动phead void SLTPrint(SLNode* phead) {SLNode* cur phead;while (cur ! NULL){printf(%d-, cur-val);cur cur-next;}printf(NULL\n); } 3.2开辟新空间 //开辟新空间 SLNode* CreateNode(SLNDataType x) {SLNode* newnode (SLNode*)malloc(sizeof(SLNode));if (newnode NULL){perror(malloc fail);exit(-1);}newnode-val x;newnode-next NULL;return newnode; } 3.3尾插 //尾插 void SLTPushBack(SLNode** pphead, SLNDataType x) {SLNode* newnode CreateNode(x);if (*pphead NULL){*pphead newnode;}else{SLNode* tail *pphead;while (tail-next ! NULL){tail tail-next;}tail-next newnode;} } 3.4头插 //头插 void SLTPushFront(SLNode** pphead, SLNDataType x) {SLNode* newnode CreateNode(x);newnode-next *pphead;*pphead newnode; } 3.5尾删 //尾删 void SLTPopBack(SLNode** pphead) {assert(*pphead);if ((*pphead)-next NULL){free(*pphead);*pphead NULL;}else{SLNode* prev NULL;SLNode* tail *pphead;while (tail-next ! NULL){prev tail;tail tail-next;}free(tail);prev-next NULL;} } 3.6头删 //头删 void SLTPopFront(SLNode** pphead) {assert(*pphead);SLNode* tmp *pphead;*pphead (*pphead)-next;free(tmp); } 3.7查找 //查找 SLNode* SLTFind(SLNode* phead, SLNDataType x) {SLNode* cur phead;while (cur){if (cur-val x){return cur;}else{cur cur-next;}}return NULL; } 3.8在pos前面插入 //在pos前面插入 void SLTInsert(SLNode** pphead, SLNode* pos, SLNDataType x) {assert(pphead);assert(pos);assert(*pphead);//assert((!pos !(*pphead)) || (pos (*pphead)));if (*pphead pos){SLTPushFront(pphead, x);}else{SLNode* prev *pphead;while (prev-next ! pos){prev prev-next;}SLNode* newnode CreateNode(x);prev-next newnode;newnode-next pos;} } 3.9删除pos位置 //删除pos位置 void SLTErase(SLNode** pphead, SLNode* pos) {assert(pphead);assert(pos);assert(*pphead);if (*pphead pos){SLTPopFront(pphead);}else{SLNode* prev *pphead;while (prev-next ! pos){prev prev-next;}prev-next pos-next;free(pos);pos NULL;} } 3.10销毁 //销毁 void SLTDestroy(SLNode** pphead) {assert(pphead);SLNode* cur *pphead;while (cur-next ! NULL){SLNode* next cur-next;free(cur);cur next;}*pphead NULL; } 3.11在pos位置之后插入 // 单链表在pos位置之后插入x void SLTInsertAfter(SLNode* pos, SLNDataType x) {SLNode* newnode CreateNode(x);newnode-next pos-next;pos-next newnode; } 3.12删除pos位置之后的值 // 单链表删除pos位置之后的值 void SLTEraseAfter(SLNode* pos) {assert(pos-next ! NULL);pos-next pos-next-next;free(pos-next);pos-next NULL; } 4.总代码 SList.h #pragma once #include stdio.h #include stdlib.h #include assert.h //创建单链表 typedef int SLNDataType; typedef struct SLNode {SLNDataType val;struct SLNode* next; }SLNode;//打印单链表 //尽量不要动phead void SLTPrint(SLNode* phead); //开辟新空间 SLNode* CreateNode(SLNDataType x);//尾插 void SLTPushBack(SLNode** pphead, SLNDataType x); //头插 void SLTPushFront(SLNode** pphead, SLNDataType x); //尾删 void SLTPopBack(SLNode** pphead); //头删 void SLTPopFront(SLNode** pphead);//查找 SLNode* SLTFind(SLNode* phead, SLNDataType x); //在pos前面插入 void SLTInsert(SLNode** pphead, SLNode* pos, SLNDataType x); //删除pos位置 void SLTErase(SLNode** pphead, SLNode* pos); // 单链表在pos位置之后插入x void SLTInsertAfter(SLNode* pos, SLNDataType x); // 单链表删除pos位置之后的值 void SLTEraseAfter(SLNode* pos);//销毁 void SLTDestroy(SLNode** pphead);SList.c #define _CRT_SECURE_NO_WARNINGS 1 #includeSList.h //打印单链表 //尽量不要动phead void SLTPrint(SLNode* phead) {SLNode* cur phead;while (cur ! NULL){printf(%d-, cur-val);cur cur-next;}printf(NULL\n); } //开辟新空间 SLNode* CreateNode(SLNDataType x) {SLNode* newnode (SLNode*)malloc(sizeof(SLNode));if (newnode NULL){perror(malloc fail);exit(-1);}newnode-val x;newnode-next NULL;return newnode; } //尾插 void SLTPushBack(SLNode** pphead, SLNDataType x) {SLNode* newnode CreateNode(x);if (*pphead NULL){*pphead newnode;}else{SLNode* tail *pphead;while (tail-next ! NULL){tail tail-next;}tail-next newnode;} } //头插 void SLTPushFront(SLNode** pphead, SLNDataType x) {SLNode* newnode CreateNode(x);newnode-next *pphead;*pphead newnode; } //尾删 void SLTPopBack(SLNode** pphead) {assert(*pphead);if ((*pphead)-next NULL){free(*pphead);*pphead NULL;}else{SLNode* prev NULL;SLNode* tail *pphead;while (tail-next ! NULL){prev tail;tail tail-next;}free(tail);prev-next NULL;} } //头删 void SLTPopFront(SLNode** pphead) {assert(*pphead);SLNode* tmp *pphead;*pphead (*pphead)-next;free(tmp); } //查找 SLNode* SLTFind(SLNode* phead, SLNDataType x) {SLNode* cur phead;while (cur){if (cur-val x){return cur;}else{cur cur-next;}}return NULL; } //在pos前面插入 void SLTInsert(SLNode** pphead, SLNode* pos, SLNDataType x) {assert(pphead);assert(pos);assert(*pphead);//assert((!pos !(*pphead)) || (pos (*pphead)));if (*pphead pos){SLTPushFront(pphead, x);}else{SLNode* prev *pphead;while (prev-next ! pos){prev prev-next;}SLNode* newnode CreateNode(x);prev-next newnode;newnode-next pos;} } //删除pos位置 void SLTErase(SLNode** pphead, SLNode* pos) {assert(pphead);assert(pos);assert(*pphead);if (*pphead pos){SLTPopFront(pphead);}else{SLNode* prev *pphead;while (prev-next ! pos){prev prev-next;}prev-next pos-next;free(pos);pos NULL;} } // 单链表在pos位置之后插入x void SLTInsertAfter(SLNode* pos, SLNDataType x) {SLNode* newnode CreateNode(x);newnode-next pos-next;pos-next newnode; } // 单链表删除pos位置之后的值 void SLTEraseAfter(SLNode* pos) {assert(pos-next ! NULL);pos-next pos-next-next;free(pos-next);pos-next NULL; } //销毁 void SLTDestroy(SLNode** pphead) {assert(pphead);SLNode* cur *pphead;while (cur-next ! NULL){SLNode* next cur-next;free(cur);cur next;}*pphead NULL; }test.c #define _CRT_SECURE_NO_WARNINGS 1 #include SList.h int main() {SLNode* plist NULL;SLTPushBack(plist, 1);SLTPushBack(plist, 2);SLTPushBack(plist, 3);SLTPushBack(plist, 4);SLTPushFront(plist, 5);SLTPrint(plist);SLTPopBack(plist);SLTPrint(plist);SLTPopFront(plist);SLTPrint(plist);SLNode* pos SLTFind(plist, 2);SLTInsert(plist, pos, 0);SLTPrint(plist);/*SLTErase(plist, pos);SLTPrint(plist);*/SLTInsertAfter(pos, 0);SLTPrint(plist);SLTEraseAfter(pos);SLTPrint(plist);SLTDestroy(plist);return 0; }
http://www.dnsts.com.cn/news/105580.html

相关文章:

  • 接视频做的网网站整合营销传播方案案例
  • 哈尔滨行业网站开发网站根目录表示
  • 数据分析和网站开发网站如何建设数据库
  • 泰安网站建设广告做网页学什么语言
  • 怎么做app网站ui原型纯html5网站
  • 企业网站建设服务商网站域名后缀cc
  • 建筑网站绿地新里城网站出现建设中
  • wordpress站点统计小工具食品网站建设规划
  • 网站浏览速度大型国企网站建设费用
  • 个人网站注册步骤图解电商网站开发目的
  • 网站建设与管理pdfc2c旅游电子商务平台
  • 代理记账 营销型网站网站设计与开发培训
  • 厦门网络推广建网站网盘手机app官网下载
  • 大朗网站建设公司安徽万振建设集团网站
  • 茶叶网站建设哪家购物网站主页模版
  • seo网站优化方案摘要哈尔滨市建设工程质量安全站
  • php网站开发建设wordpress模板用法
  • 大同市网站建设深圳建站公司需要多久
  • 深圳购物网站南充市企业网站建设
  • 建设购物网站多少钱谷德设计网官网首页入口
  • 网站建设图文Wordpress提高pagespeed
  • wordpress快速建站视频教程wordpress远程图片
  • 西宁网站建设有限公司无锡网站App微信
  • 网络建站东北做网站微信朋友圈应该怎么发
  • 沈阳网站建设q479185700棒昆明做网站建设硬件设备
  • 芜湖营销型网站制作制作网站学什么软件
  • 海淀网站制作邯郸网站建设选哪家
  • 娱乐网站排行榜百度精简版入口
  • 电脑公司网站管理系统黑龙江能源建设网站
  • 兴文县建设工程网站请人做网站注意事项