单链表的基本操作

C语言实现单链表

单链表的基本功能:

1、单链表的尾插
2、单链表的头插
3、单链表的尾删
4、单链表的头删
5、单链表的销毁
6、打印单链表
7、单链表的销毁(顺着销毁)
8、单链表的销毁(逆着销毁)
9、单链表节点的查找操作
10、单链表任意位置的插入操作
11、单链表任一节点的删除

代码实现

SList.h文件

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <malloc.h>
#include <stdlib.h>

typedef int DataType;
typedef struct SListNode{
    struct SListNode* _next;
    DataType _data;
}SListNode,*pSListNode;

void SListPushBack(pSListNode* pHead,DataType x);//链表的尾插
void SListPushFront(pSListNode* pHead,DataType x);//链表的头插
void SListPopBack(pSListNode* pHead);//链表的尾删
void SListPopFront(pSListNode* pHead);//链表的头删
void SListDestory(pSListNode* pHead);//链表的销毁
void SListPrint(pSListNode pHead);//打印链表
void SListDestory2(pSListNode* pHead);//链表的销毁(顺着销毁)
void SListDestory3(pSListNode* pHead);//链表的销毁(逆着销毁)
pSListNode SListFind(pSListNode pHead, DataType x);//链表节点的查找操作
void SListInsert(pSListNode* pHead, pSListNode pos, DataType x);//链表任意位置的插入操作
void SListEarse(pSListNode* pHead, pSListNode pos);  //链表任一节点的删除

SList.c文件

#define _CRT_SECURE_NO_WARNINGS 1
#include "SList.h"

pSListNode BuySListNode(DataType x)//创建新节点
{
    pSListNode node = (pSListNode)malloc(sizeof(SListNode));
    assert(node);
    node->_data = x;
    node->_next = NULL;
    return node;
}

void SListPrint(pSListNode pHead)//打印链表
{
    if (pHead == NULL)
    {
        printf(
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值