list的c實現(xiàn)-創(chuàng)新互聯(lián)

#pragma once

成都網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序、集團企業(yè)網(wǎng)站建設等服務項目。核心團隊均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗,服務眾多知名企業(yè)客戶;涵蓋的客戶類型包括:OPP膠袋等眾多領域,積累了大量豐富的經(jīng)驗,同時也獲得了客戶的一致夸獎!

#include<malloc.h>

#include<assert.h>

#include<stdio.h>

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;

}

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前題目:list的c實現(xiàn)-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://muchs.cn/article34/eggpe.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站建設、品牌網(wǎng)站建設、外貿(mào)建站、外貿(mào)網(wǎng)站建設、網(wǎng)站設計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設