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(