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

怎样写网站描述简约大方网站

怎样写网站描述,简约大方网站,域名申请好了 怎么做网站,接网站建设_网站设计目录 一、双向链表的结构 二、双向链表的实现 2.1 双向链表的初始化LTInit 2.2 双向链表的打印LTPrint 2.3 双向链表的判空LTEmpty 2.4 尾插LTPushBack 2.5 尾删LTPopBack 2.6 头插LTPushFront 2.7 头删LTPopFront 2.8 查找LTFind 2.9 插入LTInsert 2.10 删除LTEra…

目录

一、双向链表的结构

二、双向链表的实现

2.1 双向链表的初始化LTInit

2.2 双向链表的打印LTPrint

2.3 双向链表的判空LTEmpty

2.4 尾插LTPushBack

2.5 尾删LTPopBack

2.6 头插LTPushFront

2.7 头删LTPopFront

2.8 查找LTFind

2.9 插入LTInsert

2.10 删除LTErase

2.11 销毁LTDestroy

三、顺序表和和链表的优缺点分析

四、代码

4.1 ListNode.h

4.2 ListNode.c

4.3 test.c


一、双向链表的结构

双向链表的结构如下图所示:

二、双向链表的实现

2.1 双向链表的初始化LTInit

实现代码如下:

LTNode* BuyNode(LTDataType x) {LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));if (newnode == NULL) {perror("BuyNode()::malloc");exit(1);}newnode->next = newnode;newnode->prev = newnode;newnode->data = x;return newnode;
}
LTNode* LTInit() {return BuyNode(0);
}

2.2 双向链表的打印LTPrint

实现代码如下:

void LTPrint(LTNode* phead) {assert(phead);LTNode* cur = phead->next;while (cur != phead) {printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");}

2.3 双向链表的判空LTEmpty

实现代码如下:

bool LTEmpty(LTNode* phead) {if (phead->next == phead) {return true;}else {return false;}
}

2.4 尾插LTPushBack

实现代码如下:

LTNode* BuyNode(LTDataType x) {LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));if (newnode == NULL) {perror("BuyNode()::malloc");exit(1);}newnode->next = newnode;newnode->prev = newnode;newnode->data = x;return newnode;
}
void LTPushBack(LTNode* phead, LTDataType x) {assert(phead);LTNode* newnode = BuyNode(x);LTNode* tail = phead->prev;tail->next = newnode;newnode->prev = tail;newnode->next = phead;phead->prev = newnode;}

2.5 尾删LTPopBack

实现代码如下:

void LTPopBack(LTNode* phead)
{assert(phead);assert(LTEmpty(phead) != true);LTNode* tail = phead->prev;LTNode* pretail = tail->prev;pretail->next = phead;phead->prev = pretail;free(tail);
}

2.6 头插LTPushFront

实现代码如下:

LTNode* BuyNode(LTDataType x) {LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));if (newnode == NULL) {perror("BuyNode()::malloc");exit(1);}newnode->next = newnode;newnode->prev = newnode;newnode->data = x;return newnode;
}
void LTPushFront(LTNode* phead, LTDataType x) {assert(phead);LTNode* newnode = BuyNode(x);newnode->next = phead->next;newnode->prev = phead;phead->next = newnode;newnode->next->prev = newnode;
}

2.7 头删LTPopFront

实现代码如下:

void LTPopFront(LTNode* phead) {assert(phead);LTNode* del = phead->next;phead->next = del->next;del->next->prev = phead;free(del);
}

2.8 查找LTFind

实现代码如下:

LTNode* LTFind(LTNode* phead, LTDataType x) {assert(phead);LTNode* cur = phead->next;while (cur != phead) {if (cur->data == x) {return cur;}cur = cur->next;}return NULL;
}

2.9 插入LTInsert

实现代码如下:

void LTInsert(LTNode* pos, LTDataType x){assert(pos);LTNode* newnode = BuyNode(x);newnode->next = pos->next;newnode->prev = pos;pos->next = newnode;newnode->next->prev = newnode;}

2.10 删除LTErase

实现代码如下:

void LTErase(LTNode* pos) {assert(pos);LTNode* next = pos->next;LTNode* prev = pos->prev;next->prev = prev;prev->next = next;free(pos);
}

2.11 销毁LTDestroy

实现代码如下:

void LTDestroy(LTNode* phead) {assert(phead);LTNode* cur = phead->next;while (cur!=phead) {LTNode* next = cur->next;free(cur);cur = next;}phead->next = phead;phead->prev = phead;
}

三、顺序表和和链表的优缺点分析

不同点顺序表链表(单链表)
存储空间上物理上⼀定连续逻辑上连续,但物理上不⼀定连续
随机访问⽀持O(1)不⽀持:O(N)
任意位置插⼊或者删除元素可能需要搬移元素,效率低O(N)
只需修改指针指向
插⼊
动态顺序表,空间不够时需要扩容
没有容量的概念
应⽤场景元素⾼效存储+频繁访问任意位置插⼊和删除频繁

四、代码

4.1 ListNode.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<assert.h>
typedef int LTDataType;
typedef struct ListNode
{struct ListNode* prev;LTDataType data;struct ListNode* next;
}LTNode;//void LTInit(LTNode** pphead);
LTNode* LTInit();
void LTDestroy(LTNode* phead);
void LTPrint(LTNode* phead);
bool LTEmpty(LTNode* phead);void LTPushBack(LTNode* phead, LTDataType x);
void LTPopBack(LTNode* phead);void LTPushFront(LTNode* phead, LTDataType x);
void LTPopFront(LTNode* phead);
//在pos位置之后插入数据
void LTInsert(LTNode* pos, LTDataType x);
void LTErase(LTNode* pos);
LTNode* LTFind(LTNode* phead, LTDataType x);

4.2 ListNode.c

#define _CRT_SECURE_NO_WARNINGS 1
#include"ListNode.h"
LTNode* BuyNode(LTDataType x) {LTNode* newnode = (LTNode*)malloc(sizeof(LTNode));if (newnode == NULL) {perror("BuyNode()::malloc");exit(1);}newnode->next = newnode;newnode->prev = newnode;newnode->data = x;return newnode;
}
LTNode* LTInit() {return BuyNode(0);
}
void LTDestroy(LTNode* phead) {assert(phead);LTNode* cur = phead->next;while (cur!=phead) {LTNode* next = cur->next;free(cur);cur = next;}phead->next = phead;phead->prev = phead;
}
void LTPrint(LTNode* phead) {assert(phead);LTNode* cur = phead->next;while (cur != phead) {printf("%d->", cur->data);cur = cur->next;}printf("NULL\n");}
bool LTEmpty(LTNode* phead) {if (phead->next == phead) {return true;}else {return false;}
}void LTPushBack(LTNode* phead, LTDataType x) {assert(phead);LTNode* newnode = BuyNode(x);LTNode* tail = phead->prev;tail->next = newnode;newnode->prev = tail;newnode->next = phead;phead->prev = newnode;}
void LTPopBack(LTNode* phead)
{assert(phead);assert(LTEmpty(phead) != true);LTNode* tail = phead->prev;LTNode* pretail = tail->prev;pretail->next = phead;phead->prev = pretail;free(tail);
}void LTPushFront(LTNode* phead, LTDataType x) {assert(phead);LTNode* newnode = BuyNode(x);newnode->next = phead->next;newnode->prev = phead;phead->next = newnode;newnode->next->prev = newnode;
}
void LTPopFront(LTNode* phead) {assert(phead);LTNode* del = phead->next;phead->next = del->next;del->next->prev = phead;free(del);
}
LTNode* LTFind(LTNode* phead, LTDataType x) {assert(phead);LTNode* cur = phead->next;while (cur != phead) {if (cur->data == x) {return cur;}cur = cur->next;}return NULL;
}
//在pos位置之后插入数据
void LTInsert(LTNode* pos, LTDataType x){assert(pos);LTNode* newnode = BuyNode(x);newnode->next = pos->next;newnode->prev = pos;pos->next = newnode;newnode->next->prev = newnode;}
void LTErase(LTNode* pos) {assert(pos);LTNode* next = pos->next;LTNode* prev = pos->prev;next->prev = prev;prev->next = next;free(pos);
}

4.3 test.c

#define _CRT_SECURE_NO_WARNINGS 1
#include"ListNode.h"
void test01()//测试尾插
{LTNode* phead = LTInit();LTPushBack(phead, 1);LTPushBack(phead, 2);LTPushBack(phead, 3);LTPushBack(phead, 4);LTPrint(phead);LTDestroy(phead);
}
void test02()//测试尾删
{LTNode* phead = LTInit();LTPushBack(phead, 1);LTPushBack(phead, 2);LTPushBack(phead, 3);LTPushBack(phead, 4);LTPrint(phead);//1 2 3 4LTPopBack(phead);LTPrint(phead);//1 2 3LTPopBack(phead);LTPrint(phead);//1 2LTPopBack(phead);LTPrint(phead);//1LTPopBack(phead);LTPrint(phead);//NULLLTDestroy(phead);}
void test03()//测试头插
{LTNode* phead = LTInit();LTPushFront(phead, 1);LTPushFront(phead, 2);LTPushFront(phead, 3);LTPushFront(phead, 4);LTPrint(phead);//4 3 2 1}
void test04()//测试头删
{LTNode* phead = LTInit();LTPushFront(phead, 1);LTPushFront(phead, 2);LTPushFront(phead, 3);LTPushFront(phead, 4);LTPrint(phead);//4 3 2 1LTPopFront(phead);LTPrint(phead);LTPopFront(phead);LTPrint(phead);LTPopFront(phead);LTPrint(phead);LTPopFront(phead);LTPrint(phead);
}
void tect05()//测试查找
{LTNode* phead = LTInit();LTPushFront(phead, 1);LTPushFront(phead, 2);LTPushFront(phead, 3);LTPushFront(phead, 4);LTNode* ret = LTFind(phead, 4);if (ret == NULL) {printf("找不到\n");}else {printf("找到了\n");}ret = LTFind(phead, 9);if (ret == NULL) {printf("找不到\n");}else {printf("找到了\n");}}
void test06()//测试插入
{LTNode* phead = LTInit();LTPushFront(phead, 1);LTPushFront(phead, 2);LTPushFront(phead, 3);LTPushFront(phead, 4);LTNode* ret = LTFind(phead, 4);LTInsert(ret, 99);LTPrint(phead);ret = LTFind(phead, 1);LTInsert(ret, 88);LTPrint(phead);ret = LTFind(phead, 3);LTInsert(ret, 77);LTPrint(phead);}
void test07()//测试删除
{LTNode* phead = LTInit();LTPushFront(phead, 1);LTPushFront(phead, 2);LTPushFront(phead, 3);LTPushFront(phead, 4);LTNode* ret = LTFind(phead, 4);LTErase(ret);LTPrint(phead);ret = LTFind(phead, 3);LTErase(ret);LTPrint(phead);ret = LTFind(phead, 2);LTErase(ret);LTPrint(phead);ret = LTFind(phead, 1);LTErase(ret);LTPrint(phead);}
int main() {//test01();//测试尾插//test02();//测试尾删//test03();//测试头插//test04();//测试头删//tect05();//测试查找、//test06();//测试插入//test07();//测试删除return 0;
}


文章转载自:

http://cQvxSNKm.ntzbr.cn
http://zsU2cPRu.ntzbr.cn
http://A1uJ43Vm.ntzbr.cn
http://Dp80cJuN.ntzbr.cn
http://4AWZCQ85.ntzbr.cn
http://u9qQf7a0.ntzbr.cn
http://cUZeNbCx.ntzbr.cn
http://vJ7Itb66.ntzbr.cn
http://OX0IiuTS.ntzbr.cn
http://wIIDrVxA.ntzbr.cn
http://Tuf1kmcB.ntzbr.cn
http://3nt76pB3.ntzbr.cn
http://K7JuLvEJ.ntzbr.cn
http://9Bxfxuon.ntzbr.cn
http://fup3SssI.ntzbr.cn
http://qyHxxnnZ.ntzbr.cn
http://49gZRPmQ.ntzbr.cn
http://2nEEOYa1.ntzbr.cn
http://T66dcTWb.ntzbr.cn
http://USq0PMGf.ntzbr.cn
http://Bp3h2sQi.ntzbr.cn
http://TFcYcxBG.ntzbr.cn
http://QTHChYmm.ntzbr.cn
http://enriXMsN.ntzbr.cn
http://yfHkKHI5.ntzbr.cn
http://zmSXnO9E.ntzbr.cn
http://jmyylBHX.ntzbr.cn
http://BjlLJKSj.ntzbr.cn
http://Cvtlj7gy.ntzbr.cn
http://5HtHjmbZ.ntzbr.cn
http://www.dtcms.com/wzjs/698805.html

相关文章:

  • 禁止指定ip访问网站那家网站做的效果好
  • 佛山市外贸网站建设搭建网站需要学什么软件
  • 做网站必须要买空间上海 装修公司推荐
  • 网站建设办公怎么注册域名免费
  • 什么网站可以做报名系统wordpress速度慢解决方法
  • 怎么做网站服务器专业建站方案
  • 什么是网站二级目录企业网站建设计划
  • 小型求职招聘网站源码 phpwordpress小工具开发教程
  • 外贸商城网站系统临汾做网站的公司
  • 网站设计建设公司教程软件开发接单网站
  • 这么用自己的电脑做网站服务器网站建设合同建设方注意事项
  • 保定模板建站平台什邡门户网站
  • 020网站开发兰州网站设计有限公司
  • 摄影网站建立购买空间后怎么上传网站
  • 网站设计者哈尔滨seo优化
  • 小榄网站建设公司html5手机网站开发教程
  • 腾冲网站建设建设公司网站都需要什么科目
  • 地方门户网站如何宣传电商网站建设流程图
  • 网站备案 影响wordpress 模版 推荐
  • 企业建站 炫酷模板一人有限公司怎么注册
  • 郴州网站建设公司官网网站如何防止重登录
  • 企业网站建设的困难和问题甘肃第九建设集团公司网站
  • 网站主机的类型网站程序更换
  • 天津的公司能在北京做网站备案吗高大上网站欣赏
  • 做宣传网站大概多少钱800多块做网站
  • 网站seo快排软件免费制作短视频软件
  • 宣传型网站建设网页布局设计的一般步骤
  • 做网站推广我们是专业的泉州服装电商网站建设
  • 建一个网站大约需要花费多少钱怎么做淘宝客个人网站
  • vue网站引导页怎么做公司网站不备案和备案有什么区别