list的c实现-创新互联-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
list的c实现-创新互联

#pragma once

成都网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。核心团队均拥有互联网行业多年经验,服务众多知名企业客户;涵盖的客户类型包括:OPP胶袋等众多领域,积累了大量丰富的经验,同时也获得了客户的一致夸奖!

#include

#include

#include

typedef struct ListNode

{

int _data;

struct ListNode* _next;

}ListNode;

void InitList(ListNode** pHead)

{

*pHead = NULL;

}

void DestoryList(ListNode** pHead)

{

ListNode* tmp = *pHead;

while (tmp)

{

free(tmp);

tmp = tmp->_next;

}

*pHead = NULL;

}

ListNode* BuyNode(int data)

{

ListNode* newNode = (ListNode*)malloc(sizeof(ListNode));

assert(newNode);

newNode->_data = data;

newNode->_next = NULL;

return newNode;

}

void PushBack(ListNode** pHead, int data)

{

assert(pHead);

if (*pHead == NULL)

{

*pHead = BuyNode(data);

return;

}

ListNode* tmp = *pHead;

while (tmp)

{

tmp->_next;

}

tmp = BuyNode(data);

}

void PrintList(ListNode* pHead)

{

assert(pHead);

ListNode* tmp = pHead;

while (tmp)

{

printf("%d->", tmp->_data);

tmp = tmp->_next;

}

printf("%p\n", tmp);

}

void PushFront(ListNode** pHead, int data)

{

assert(pHead);

ListNode* tmp = *pHead;

*pHead = BuyNode(data);

(*pHead)->_next = tmp;

}

void PopBack(ListNode** pHead)

{

assert(pHead);

if (*pHead == NULL)

return;

ListNode* tmp = *pHead;

while (tmp->_next != NULL)

{

tmp = tmp->_next;

}

free(tmp);

tmp = NULL;

}

void PopFront(ListNode** pHead)

{

assert(pHead);

if (*pHead == NULL)

return;

ListNode* del = *pHead;

*pHead = (*pHead)->_next;

free(del);

}

ListNode* FindNode(ListNode** pHead, int data)

{

assert(pHead);

if (*pHead == NULL)

return NULL;

ListNode* tmp = *pHead;

while (tmp->_next != NULL)

{

if (tmp->_data == data)

return tmp;

tmp = tmp->_next;

}

return NULL;

}

void Insert(ListNode* pos, int data)

{

assert(pos);

ListNode*newnode = BuyNode(data);

newnode->_next = pos->_next;

pos->_next = newnode;

}

void Erase(ListNode** pHead, ListNode*pos)

{

assert(pHead);

assert(pos);

if (*pHead == NULL)

return;

ListNode* tmp = *pHead;

while (tmp->_next != NULL)

{

if (tmp->_next == pos)

{

tmp->_next = pos->_next;

free(pos);

break;

}

tmp = tmp->_next;

}

}

void DelNonTailNode(ListNode* pos)

{

assert(pos&&pos->_next);

ListNode* next = pos->_next->_next;

pos->_data = pos->_next->_data;

free(pos->_next);

pos->_next = next;

}

void remove(ListNode** pHead, int data)

{

assert(pHead);

if (*pHead == NULL)

return;

ListNode* del = FindNode(pHead,data);

if (del != NULL)

{

Erase(pHead, del);

}

return;

}

void Reverse(ListNode** pHead)

{

ListNode* cur = *pHead;

ListNode* head = NULL;

ListNode* tmp;

while (cur)

{

tmp = cur;

cur = cur->_next;

tmp->_next = head;

head = tmp;

}

*pHead = head;

}

void InsertFrontNode(ListNode* pos,int data)//假装加到pos前面其实就是data交换

{

assert(pos);

ListNode* newnode = BuyNode(pos->_data);

newnode->_next = pos->_next;

pos->_next = newnode;

pos->_data = data;

}

ListNode* FindMidNode(ListNode** pHead)

{

assert(pHead);

if (*pHead == NULL)

{

return NULL;

}

ListNode* slow = *pHead;

ListNode* fast = *pHead;

while (fast->_next&&fast)

{

slow = slow->_next;

fast = fast->_next->_next;

}

return slow;

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:list的c实现-创新互联
本文地址:http://scgulin.cn/article/eggpe.html