# 单链表各种操作的代码实现

SList.h:包的引用和函数的声明

SList.c:各个操作的实现

SList.c:各个操作的实现

### SList.h：

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

typedef int SLTDataType;
struct SListNode
{
SLTDataType data;             //链表的数据
struct SListNode* next;       //链表的指针
};
typedef struct SListNode  SLTNode;//改个名字

void SListInsert(SLTNode** pphead, int pos, SLTDataType x);//在任意位置插入


### SList.c:

#define _CRT_SECURE_NO_WARNINGS 1
#include"SList.h"

{
SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
newnode->data = x;
newnode->next = NULL;
return newnode;
}
{
{
while (cur != NULL)
{
printf("%d->", cur->data);
cur = cur->next;
}
printf("NULL\n");
}
else
{
printf("您输入的链表为空");
}
}
{
{
}
else
{
//找尾节点的指针
while (tail->next != NULL)
{
tail = tail->next;
}
tail->next = newnode;
}
}
{
}
{
return;
else
{
free(tmp);
}
}

{
{
return;
}
else if (tmpt->next == NULL)
{
}
else
{
//SLTNode* tmpt2 = tmpt->next;
while (tmpt->next->next != NULL)
{
tmpt = tmpt->next;
}
free(tmpt->next);
tmpt->next = NULL;
}
}

void SListInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x)//在任意结点之前插入数据
{
{
newnode->next = NULL;
}
{
}
else
{
while (tmpt->next != pos)
{
tmpt = tmpt->next;
}
tmpt->next = newnode;
newnode->next = pos;
}

}

{
while (cur)
{
if (cur->data == x)
return cur;
else
cur = cur->next;
}
return NULL;
}

{
{
return;
}
{

free(cur);
cur = NULL;
}
else
{
while (cur->next != pos)
{
cur = cur->next;
}
cur->next = pos->next;
free(pos);
}

}


### Test.c：

#pragma once
#include"SList.h"

test1()
{
//想在1前面插入0.
if (pos != NULL)
{
}
else
printf("没有找到您要找的位置");
//想要删除链表中的2.
if (pos2 != NULL)
{
}