您的位置:首页 > 游戏 > 手游 > 泉州企业自助建站系统_江西龙南疫情_竞价推广套户渠道商_郑州网络营销推广公司

泉州企业自助建站系统_江西龙南疫情_竞价推广套户渠道商_郑州网络营销推广公司

2024/11/19 4:38:01 来源:https://blog.csdn.net/m0_37567738/article/details/143624179  浏览:    关键词:泉州企业自助建站系统_江西龙南疫情_竞价推广套户渠道商_郑州网络营销推广公司
泉州企业自助建站系统_江西龙南疫情_竞价推广套户渠道商_郑州网络营销推广公司

双向循环列表的实现。
根据定义实现。不解释,具体细节看代码。

list.h

#pragma once#pragma pack(1)typedef struct _MyListEntry {_MyListEntry* next;_MyListEntry* prev;
}MyListEntry;#pragma pack()class MyListClass {
public:MyListEntry* m_list=0;int m_keyOffset;int m_keySize;MyListClass();~MyListClass();int InsertEnd(MyListEntry* list);int InsertHead(MyListEntry* list);MyListEntry* Search(int offset,char * data,int size);int Remove(MyListEntry* list);};

list.cpp


#include "list.h"
#include <Windows.h>MyListClass::MyListClass() {m_list = new MyListEntry;m_list->next = 0;m_list->prev = 0;m_keyOffset = 0;m_keySize = 0;
}MyListClass::~MyListClass() {MyListEntry* n = m_list->next;MyListEntry* b = n;do{if (n == 0) {break;}MyListEntry* t = n;n = n->next;delete t;} while (n != b);if (m_list) {delete m_list;}
}MyListEntry* MyListClass::Search(int offset,char * data,int size) {if (data == 0 || size == 0) {return 0;}MyListEntry* n = m_list->next;MyListEntry* b = n;do{if (n == 0) {break;}char* obj = (char*)((char*)n + offset);if (memcmp(data, obj,size) == 0) {return n;}n = n->next;} while (n != b);return 0;
}int MyListClass::InsertHead(MyListEntry* list) {if (list == 0) {return 0;}MyListEntry* n = m_list->next;MyListEntry* p = m_list->prev;if (n == 0 || p == 0) {m_list->next = list;m_list->prev = list;list->prev = list;list->next = list;return 0;}p->next = list;n->prev = list;list->prev = p;list->next = n;m_list->next = list;return TRUE;
}int MyListClass::InsertEnd(MyListEntry* list) {if (list == 0) {return 0;}MyListEntry* n = m_list->next;MyListEntry* p = m_list->prev;if (n == 0 || p == 0) {m_list->next = list;m_list->prev = list;list->next = list;list->prev = list;return TRUE;}p->next = list;n->prev = list;list->prev = p;list->next = n;m_list->prev = list;return TRUE;
}int MyListClass::Remove(MyListEntry* list) {if (list == 0 || list == m_list) {return 0;}if (list == m_list->next) {MyListEntry* p = m_list->prev;if (p == list) {m_list->next = 0;m_list->prev = 0;}else {MyListEntry* n = m_list->next->next;n->prev = p;p->next = n;m_list->next = n;}delete list;		return TRUE;}else if (list == m_list->prev) {MyListEntry* n = m_list->next;	if (list == n) {m_list->next = 0;m_list->prev = 0;}else {MyListEntry* p = m_list->prev->prev;		n->prev = p;p->next = n;m_list->prev = p;}delete list;return TRUE;}MyListEntry* n = m_list->next;MyListEntry* b = n;do{if (list == n) {MyListEntry* prev = n->prev;MyListEntry* next = n->next;prev->next = next;next->prev = prev;delete list;return TRUE;}n = n->next;} while (n != b);return FALSE;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com