#pragma once
#include<assert.h>
#include<malloc.h>
#include<stdio.h>
typedef int Datatype;
typedef struct SHListNode
{
struct SHListNode* next;
Datatype data;}Node;
Node* BuySHListNode(Datatype data);
void SHListInit(Node** pHead);
void SHListPushBack(Node* pHead, Datatype data);
void SHListPopBack(Node* pHead);
void SHListPushFront(Node* pHead, Datatype data);
void SHListPopFront(Node* pHead);
void SHListDestroy(Node* pHead);
#include "SHList.h"
Node* BuySHListNode(Datatype data)
{
Node* pNewNode = (Node*)malloc(sizeof(Node));
if (NULL == pNewNode)
{
assert(0);
return NULL;
}
pNewNode->data = data;
pNewNode->next = NULL;
return pNewNode;}
void SHListInit(Node** pHead)
{
pHead = BuySHListNode(0);
}
void SHListPushBack(Node* pHead, Datatype data)
{
Node* pTailNode = pHead;
assert(pHead);
while (pTailNode->next)
pTailNode = pTailNode->next;
pTailNode->next = BuySHListNode(data);}
void SHListPopBack(Node* pHead)
{
Node* pTailNode = pHead;
Node* pPreTail = NULL;
assert(pHead);
if (NULL == pHead->next)
return;
while (pTailNode->next)
{
pPreTail = pTailNode;
pTailNode = pTailNode->next;
}
free(pTailNode);
pPreTail->next = NULL;
}
void SHListPushFront(Node* pHead, Datatype data)
{
Node* pNewNode = NULL;
assert(pHead);
pNewNode->next = pHead->next;
pHead->next = pNewNode;
}
void SHListPopFront(Node* pHead)
{
Node* pDelNode = NULL;
assert(pHead);
if (NULL == pHead->next)
return;
pDelNode = pHead->next;
pHead->next = pDelNode->next;
free(pDelNode);
}
void SHListDestroy(Node* pHead)
{
assert(pHead);
free(pHead);
pHead = NULL;
}
#include"SHList.h"
int main()
{
return;
}