您的位置:首页 > 教育 > 培训 > 有发展的小企业网站建设_如何弄一个自己的小程序_影响seo排名的因素有哪些_有实力的网站排名优化软件

有发展的小企业网站建设_如何弄一个自己的小程序_影响seo排名的因素有哪些_有实力的网站排名优化软件

2025/5/3 19:47:51 来源:https://blog.csdn.net/m0_65148485/article/details/144323527  浏览:    关键词:有发展的小企业网站建设_如何弄一个自己的小程序_影响seo排名的因素有哪些_有实力的网站排名优化软件
有发展的小企业网站建设_如何弄一个自己的小程序_影响seo排名的因素有哪些_有实力的网站排名优化软件

目录

1,单链表的定义

2,单链表的实现

A,函数的声明

B,函数的定义


1,单链表的定义

链表是一种物理存储结构上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的 。

链表一般可以分为:

1,无头单向非循环链表:结构简单,一般不会单独用来存数据。实际中更多是作为其他数据结构的子结构,如哈希桶、图的邻接表等等。

2,带头双向循环链表:结构复杂,一般用在单独存储数据。实际中使用的链表数据结构,都是带头双向链表。

2,单链表的实现

A,函数的声明

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>typedef int SLDataType; //数据类型
typedef struct SListNode//单向链表
{SLDataType data;        //存储数据struct SListNode* next; //下节点地址
}SLTNode;//遍历链表/创建节点/尾插/头插/尾删/头删
void SListPrint(SLTNode* phead);
SLTNode* BuySListNode(SLDataType x);
void SListPushBack(SLTNode** pphead, SLDataType x);
void SListPushFront(SLTNode** pphead, SLDataType x);
void SListPopBack(SLTNode** pphead);
void SListPopFront(SLTNode** pphead);// 按值查找/在pos位置之前插入节点/删除pos位置的节点
SLTNode* SListFind(SLTNode* phead, SLDataType x);
void SListPosInsert(SLTNode** pphead, SLTNode* pos, SLDataType x);
void SListPosErase(SLTNode** pphead, SLTNode* pos);

B,函数的定义

void SListPrint(SLTNode* phead)
{SLTNode* cur = phead;while (cur != NULL){printf("%d->",cur->data);cur = cur->next;}printf("NULL\n");
}SLTNode* BuySListNode(SLDataType x)
{SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));assert(newnode);newnode->data = x;newnode->next = NULL;return newnode;
}void SListPushBack(SLTNode** pphead, SLDataType x)
{//建立新节点SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));assert(newnode);newnode->data = x;newnode->next = NULL;//链表为空的情况if (*pphead == NULL){*pphead = newnode;}else{//找尾节点SLTNode* tail = *pphead;while (tail->next != NULL){tail = tail->next;}//建立连接tail->next = newnode;}
}void SListPushFront(SLTNode** pphead, SLDataType x)
{SLTNode* newnode = BuySListNode(x);newnode->next = *pphead;*pphead = newnode;
}void SListPopBack(SLTNode** pphead)
{//链表为空的情况assert(*pphead != NULL);//只有一个节点if ((*pphead)->next == NULL){free(*pphead);*pphead = NULL;}else{//多个节点SLTNode* tail = *pphead;while (tail->next->next != NULL){tail = tail->next;}free(tail->next);tail->next = NULL;}
}void SListPopFront(SLTNode** pphead)
{assert(*pphead != NULL);SLTNode* next = (*pphead)->next;free(*pphead);*pphead = next;
}SLTNode* SListFind(SLTNode* phead, SLDataType x)
{SLTNode* cur = phead;while(cur){if (cur->data == x)return cur;cur = cur->next;}return 0;
}void SListPosInsert(SLTNode** pphead, SLTNode* pos, SLDataType x)
{assert(*pphead);assert(pos);SLTNode* newnode = BuySListNode(x);//头插if (*pphead == pos){newnode->next = *pphead;*pphead = newnode;}else{//找posSLTNode* cur = *pphead;while (cur->next != pos){cur = cur->next;}cur->next = newnode;newnode->next = pos;}
}void SListPosErase(SLTNode** pphead, SLTNode* pos)
{assert(*pphead);assert(pos);//头删if (*pphead == pos){SLTNode* next = (*pphead)->next;free(*pphead);*pphead = next;}else{SLTNode* prev = *pphead;while (prev->next != pos){prev = prev->next;}prev->next = pos->next;free(pos);}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com