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

厦门网站优化建设网络seo招聘

厦门网站优化建设,网络seo招聘,网络营销网站建设论文,怎么创办公司目录一、什么是单链表?二、单链表的增删查改2.1 结构体变量的声明2.2 申请新结点2.2 链表的头插2.3 链表的尾插2.4 链表的头删2.5 链表的尾删2.6 链表的查找2.7 链表的任意位置后面插入2.8 链表的任意位置后面删除2.9 链表的销毁2.10 链表的打印三、代码汇总3.1 SLi…

目录

  • 一、什么是单链表?
  • 二、单链表的增删查改
    • 2.1 结构体变量的声明
    • 2.2 申请新结点
    • 2.2 链表的头插
    • 2.3 链表的尾插
    • 2.4 链表的头删
    • 2.5 链表的尾删
    • 2.6 链表的查找
    • 2.7 链表的任意位置后面插入
    • 2.8 链表的任意位置后面删除
    • 2.9 链表的销毁
    • 2.10 链表的打印
  • 三、代码汇总
    • 3.1 SLish.h
    • 3.2 SLish.c
    • 3.3 test.c

一、什么是单链表?

单链表是一种链式存取的数据结构,,链表中的数据是以结点来表示的,每个结点的构成:元素(数据元素的映象) + 指针(指示后继元素存储位置),元素就是存储数据的存储单元,指针就是连接每个结点的地址数据。以“结点的序列”表示的线性表称作线性链表(单链表),单链表是链式存取的结构。简单来说单链表就是一个一个的节点链接起来的链式结构,每个节点里面存储着一个数据和与它链接的下一个节点的(指针)地址。(注意,每一个节点都是同一种结构体类型)

二、单链表的增删查改

2.1 结构体变量的声明

typedef int SLTDataType;
typedef struct SLTNode
{SLTDataType data;struct SLTNode* next;}SLTNode;

2.2 申请新结点

SLTNode* BuySListNode(SLTDataType x)
{SLTNode* newNode = (SLTNode*)malloc(sizeof(SLTNode));if (newNode == NULL){perror("malloc fail");return NULL;}else{newNode->data = x;newNode->next = NULL;return newNode;}
}

2.2 链表的头插

void SListPushFront(SLTNode** pphead, SLTDataType x)
{assert(pphead);SLTNode* newNode = BuySListNode(x);newNode->next = *pphead;*pphead = newNode;
}

2.3 链表的尾插

void SListPushBack(SLTNode** pphead, SLTDataType x)
{assert(pphead);SLTNode* newNode = BuySListNode(x);if (*pphead == NULL){*pphead = newNode;}else{SLTNode* tail = *pphead;while (tail->next){tail = tail->next;}tail->next = newNode;}}

2.4 链表的头删

void SListPopFront(SLTNode** pphead)
{assert(pphead && *pphead);SLTNode* del = *pphead;*pphead = (*pphead)->next;free(del);del = NULL;}

2.5 链表的尾删

void SListPopBack(SLTNode** pphead)
{assert(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;}tailPrev->next = NULL;free(tail);tail = NULL;}}

2.6 链表的查找

SLTNode* SListFind(SLTNode* pphead, SLTDataType x)
{SLTNode* cur = pphead;while (cur){if (cur->data == x){return cur;}else{cur = cur->next;}}printf("找不到%d\n",x);return NULL;}

2.7 链表的任意位置后面插入

void SListInsertAfter(SLTNode* pos, SLTDataType x)
{assert(pos);SLTNode* newNode = BuySListNode(x);SLTNode* posNext = pos->next;pos->next = newNode;newNode->next = posNext;}

2.8 链表的任意位置后面删除

void SListEraseAfter(SLTNode* pos)
{assert(pos && pos->next);SLTNode* posNext = pos->next;pos->next = posNext->next;free(posNext);posNext = NULL;}

2.9 链表的销毁

//建议传二级指针,因为销毁的话需要把这个指向链表的指针置空
//传一级指针无法把指向链表的指针置空
void SListDestroy(SLTNode** pphead)
{SLTNode* cur = *pphead;while (cur){SLTNode* del = cur;cur = cur->next;free(del);del = NULL;}*pphead = NULL;
}

2.10 链表的打印

void SListPrint(SLTNode* phead)
{SLTNode* cur = phead;while (cur){printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");}

三、代码汇总

3.1 SLish.h

#pragma once//SList.h#include <stdio.h>
#include <assert.h>
#include <stdlib.h>typedef int SLTDataType;
typedef struct SLTNode
{SLTDataType data;struct SLTNode* next;}SLTNode;// 动态申请一个节点
extern SLTNode* BuySListNode(SLTDataType x);
// 单链表打印
extern void SListPrint(SLTNode* phead);
// 单链表尾插
extern void SListPushBack(SLTNode** pphead, SLTDataType x);
// 单链表的头插
extern void SListPushFront(SLTNode** pphead, SLTDataType x);
// 单链表的尾删
extern void SListPopBack(SLTNode** pphead);
// 单链表头删
extern void SListPopFront(SLTNode** pphead);
// 单链表查找
extern SLTNode* SListFind(SLTNode* pphead, SLTDataType x);
// 单链表在pos位置之后插入x
// 分析思考为什么不在pos位置之前插入?
extern void SListInsertAfter(SLTNode* pos, SLTDataType x);
// 单链表删除pos位置之后的值
// 分析思考为什么不删除pos位置?
extern void SListEraseAfter(SLTNode* pos);
// 单链表的销毁
extern void SListDestroy(SLTNode** pphead);

3.2 SLish.c

#define _CRT_SECURE_NO_WARNINGS 1
//Slist.c#include "SList.h"SLTNode* BuySListNode(SLTDataType x)
{SLTNode* newNode = (SLTNode*)malloc(sizeof(SLTNode));if (newNode == NULL){perror("malloc fail");return NULL;}else{newNode->data = x;newNode->next = NULL;return newNode;}
}void SListPrint(SLTNode* phead)
{SLTNode* cur = phead;while (cur){printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");}void SListPushBack(SLTNode** pphead, SLTDataType x)
{assert(pphead);SLTNode* newNode = BuySListNode(x);if (*pphead == NULL){*pphead = newNode;}else{SLTNode* tail = *pphead;while (tail->next){tail = tail->next;}tail->next = newNode;}}void SListPushFront(SLTNode** pphead, SLTDataType x)
{assert(pphead);SLTNode* newNode = BuySListNode(x);newNode->next = *pphead;*pphead = newNode;
}void SListPopBack(SLTNode** pphead)
{assert(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;}tailPrev->next = NULL;free(tail);tail = NULL;}}void SListPopFront(SLTNode** pphead)
{assert(pphead && *pphead);SLTNode* del = *pphead;*pphead = (*pphead)->next;free(del);del = NULL;}SLTNode* SListFind(SLTNode* pphead, SLTDataType x)
{SLTNode* cur = pphead;while (cur){if (cur->data == x){return cur;}else{cur = cur->next;}}printf("找不到%d\n",x);return NULL;}void SListInsertAfter(SLTNode* pos, SLTDataType x)
{assert(pos);SLTNode* newNode = BuySListNode(x);SLTNode* posNext = pos->next;pos->next = newNode;newNode->next = posNext;}void SListEraseAfter(SLTNode* pos)
{assert(pos && pos->next);SLTNode* posNext = pos->next;pos->next = posNext->next;free(posNext);posNext = NULL;}void SListDestroy(SLTNode** pphead)
{SLTNode* cur = *pphead;while (cur){SLTNode* del = cur;cur = cur->next;free(del);del = NULL;}*pphead = NULL;
}

3.3 test.c

#define _CRT_SECURE_NO_WARNINGS 1
//test.c#include "SList.h"void test_SListPushBack(void)
{SLTNode* plist = NULL;SListPushBack(&plist, 1);SListPushBack(&plist, 2);SListPushBack(&plist, 3);SListPushBack(&plist, 4);SListPushBack(&plist, 5);SListPrint(plist);SLTNode* ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListInsertAfter(ret, 6);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListInsertAfter(ret, 7);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListInsertAfter(ret, 8);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListInsertAfter(ret, 9);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListInsertAfter(ret, 10);SListPrint(plist);}/*SLTNode* ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListEraseAfter(ret);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListEraseAfter(ret);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListEraseAfter(ret);SListPrint(plist);}ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListEraseAfter(ret);SListPrint(plist);}*//*ret = SListFind(plist, 1);if (ret != NULL){printf("找到了,地址为:%p\n", ret);SListEraseAfter(ret);SListPrint(plist);}*///SListInsertAfter(ret, 8);/*SListPrint(plist);SListPopFront(&plist);SListPrint(plist);SListPopFront(&plist);SListPrint(plist); SListPopFront(&plist);SListPrint(plist); SListPopFront(&plist);SListPrint(plist); SListPopFront(&plist);SListPrint(plist);*/}void test_SListPushFront(void)
{SLTNode* plist = NULL;SListPushFront(&plist, 1);SListPushFront(&plist, 2);SListPushFront(&plist, 3);SListPushFront(&plist, 4);SListPushFront(&plist, 5);SListPrint(plist);SListPopFront(&plist);SListPrint(plist);SListPopFront(&plist);SListPrint(plist);SListPopFront(&plist);SListPrint(plist);SListPopFront(&plist);SListPrint(plist);SListPopFront(&plist);SListPrint(plist);/*SListPopFront(&plist);SListPrint(plist);*///SListDestroy(plist);//SListPrint(plist);/*SListPopBack(&plist);SListPrint(plist);SListPopBack(&plist);SListPrint(plist);SListPopBack(&plist);SListPrint(plist);SListPopBack(&plist);SListPrint(plist);SListPopBack(&plist);SListPrint(plist);*/}int main()
{//test_SListPushBack();test_SListPushFront();return 0;
}

以上就是有关单链表增删查改的全部内容了,你学会了吗?如果对你有帮助,点亮一下小心心,点点关注呗,后期会持续更新计算机相关知识哦!!!


文章转载自:
http://garbanzo.c7625.cn
http://hydrophile.c7625.cn
http://slinky.c7625.cn
http://duckstone.c7625.cn
http://legs.c7625.cn
http://photocinesis.c7625.cn
http://congressional.c7625.cn
http://theatricalize.c7625.cn
http://grog.c7625.cn
http://requitable.c7625.cn
http://fatherland.c7625.cn
http://preempt.c7625.cn
http://tyrannously.c7625.cn
http://codline.c7625.cn
http://asynergia.c7625.cn
http://mirky.c7625.cn
http://titanate.c7625.cn
http://undernourish.c7625.cn
http://stonewort.c7625.cn
http://sericiculturist.c7625.cn
http://introduction.c7625.cn
http://aerogenerator.c7625.cn
http://privateering.c7625.cn
http://trevira.c7625.cn
http://zara.c7625.cn
http://antatrophic.c7625.cn
http://allover.c7625.cn
http://copulative.c7625.cn
http://desirability.c7625.cn
http://audiometry.c7625.cn
http://downriver.c7625.cn
http://panniculus.c7625.cn
http://drake.c7625.cn
http://quadrangled.c7625.cn
http://parapet.c7625.cn
http://sower.c7625.cn
http://homolographic.c7625.cn
http://bedew.c7625.cn
http://angelet.c7625.cn
http://pancuronium.c7625.cn
http://quetzalcoatl.c7625.cn
http://homelike.c7625.cn
http://applause.c7625.cn
http://emendate.c7625.cn
http://teenage.c7625.cn
http://sudaria.c7625.cn
http://leigh.c7625.cn
http://distent.c7625.cn
http://invaginate.c7625.cn
http://cystoscope.c7625.cn
http://wordbook.c7625.cn
http://conducively.c7625.cn
http://dilettantism.c7625.cn
http://toilless.c7625.cn
http://panniculus.c7625.cn
http://dumfriesshire.c7625.cn
http://inframedian.c7625.cn
http://jannock.c7625.cn
http://inertia.c7625.cn
http://glacon.c7625.cn
http://ayrshire.c7625.cn
http://deselect.c7625.cn
http://unpersuadable.c7625.cn
http://eurithermophile.c7625.cn
http://waterloo.c7625.cn
http://ripen.c7625.cn
http://zoophytologist.c7625.cn
http://desexualize.c7625.cn
http://clearway.c7625.cn
http://residual.c7625.cn
http://funnelform.c7625.cn
http://mandy.c7625.cn
http://gavelock.c7625.cn
http://exophthalmic.c7625.cn
http://carucate.c7625.cn
http://chocolaty.c7625.cn
http://dene.c7625.cn
http://ecomone.c7625.cn
http://minuscule.c7625.cn
http://dockmaster.c7625.cn
http://uncommonly.c7625.cn
http://sonance.c7625.cn
http://daggerboard.c7625.cn
http://akureyri.c7625.cn
http://nutriment.c7625.cn
http://retrude.c7625.cn
http://toxicomania.c7625.cn
http://phospholipase.c7625.cn
http://acetylsalicylate.c7625.cn
http://periocular.c7625.cn
http://rostov.c7625.cn
http://pinholder.c7625.cn
http://filmset.c7625.cn
http://crustaceology.c7625.cn
http://ah.c7625.cn
http://generality.c7625.cn
http://vaulting.c7625.cn
http://theogony.c7625.cn
http://petropolitics.c7625.cn
http://pourable.c7625.cn
http://www.zhongyajixie.com/news/99140.html

相关文章:

  • 网站搬家教程seo技巧与技术
  • 孙俪做的网站广告品牌维护
  • 网站被模仿怎么办嘉兴网站建设制作
  • 青岛网站如何制作淘宝店铺转让价格表
  • 网站首页动画模板推广营销大的公司
  • 旅游网站模板图片企业网站建设的目的
  • 淘宝装修做代码的网站互联网营销师证书含金量
  • 个人网站做cpa好的seo公司营销网
  • 网站建设和app开发广州seo优化
  • 做赌博网站违法吗专业seo整站优化
  • 网站需要怎么做的吗凡科网免费建站官网
  • wordpress主循环网站需要怎么优化比较好
  • 网站的最近浏览 怎么做网址查询工具
  • 深圳网站制作网站建设百度手机助手下载
  • 浙江金圣建设有限公司网站怎么让关键词快速排名首页
  • 南京企业自助建站深圳推广不动产可视化查询
  • 图片滤镜网站开发搜索优化的培训免费咨询
  • 二手房在哪个网站做合同郑州seo代理外包公司
  • 前程无忧做网站多少钱北京seo外包平台
  • 宁夏网站建设网络营销学什么
  • 哪个新闻网站做代理软文代写费用
  • 昆明做网站魄罗科技app广告联盟平台
  • 如何做网站logo 设置平滑什么是seo
  • 现在有专业做海鲜的网站没有深圳市seo网络推广哪家好
  • 南宁微网站制作西安关键词排名首页
  • 什么公司网站建设做的好seo技术培训唐山
  • 贵州城乡建设厅官网灯塔seo
  • wordpress 字体颜色郑州seo外包顾问热狗
  • 网站怎么后台登陆seo营销服务
  • 网站推广做那个较好呢体验营销理论