链表-----创建链表、正向打印、反向打印、删除结点、链表尾增加结点
#include<iostream>
#include<stdio.h>
#include<stack>
using namespace std;
struct ListNode
{
int value;
ListNode *next;
};
//创建链表
ListNode* CreatList()
{
ListNode* pHead = new ListNode();
ListNode *rear = pHead;
pHead->value = 0;
for (int i = 1;i < 10;++i)
{
ListNode *p = new ListNode();
p->value = i;
rear->next = p;
rear = p;
p = p->next;
}
rear->next = nullptr;
return pHead;
}
//打印链表
void PrintList(ListNode* Head)
{
if (Head == nullptr)
return;
while (Head != nullptr)
{
printf("%d ", Head->value);
Head = Head->next;
}
printf("\n");
}
//在链表结尾增加结点
void AddToTail(ListNode *pHead, int value)
{
ListNode* pNew = new ListNode();
pNew->value = value;
pNew->next = nullptr;
if (pHead == nullptr)
pHead = pNew;
else