最详细的链表的“增删查改“(C语言实现)

这篇博客介绍了如何使用C语言实现单链表的基本操作,包括创建节点、尾插、头插、尾删、头删、查找、插入和删除节点。还提供了一个简单的main函数来测试这些操作。博客通过源代码详细阐述了单链表的数据结构和操作方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



小伙伴可以自行调试哦

一、头文件(STlist.h)

#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef int SListDataType;//定义int类型

typedef struct SListNode
{
   
	SListDataType data;
	struct SListNode* next;//存储下一个节点的信息
}SListNode;
//打印节点信息
void SListPrint(SListNode* phead);
//创建一个节点
SListNode* BuySListNode(SListDataType x);
//尾插一个节点
void SListPushBack(SListNode** pphead, SListDataType x);
//头插一个节点
void SListPushFront(SListNode** pphead, SListDataType x);
//尾删一个节点
void SListPopBack(SListNode** pphead);
//头删一个节点
void SListPopFront(SListNode** pphead);
//单链表查找
SListNode* SListFind(SListNode* phead, SListDataType x);
//在单链表pos之前插入x
void SListInsertBefore(SListNode** pphead, SListNode* pos, SListDataType x);
//在单链表pos之后插入x
void SListInsertAfter(SListNode* pos, SListDataType x);
//单链表删除pos位置之前的值
void SListEraseBefore(SListNode** pphead, SListNode* pos);
//单链表删除pos位置之后的值
void SListEraseAfter(SListNode* pos);
//销毁单链表
void SListDestory(SListNode** pphead);

二、实现函数(STlist.c)

assert:断言

#include "STlist.h"

void SListPrint(SListNode* phead)
{
   
	SListNode* cur = phead;
	while (cur != NULL)
	{
   
		printf("%d->", cur->data);
		cur = cur->next;
	}
	printf("NULL\n"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值