#include <iostream>
#include <Windows.h>
#include <algorithm>
#define SIZE_NODE?4
#define MAX_COUNT?10
BYTE?g_szBuff[SIZE_NODE*MAX_COUNT];
UINT32?g_nCount;
void Insert(UINT32 number);
void Remove(UINT32 number);
bool Find(UINT32 number);
using namespace std;
int main(int ,char *[])
{
?memset(g_szBuff,0,SIZE_NODE*MAX_COUNT);
?g_nCount=0;
?Insert(5);
?Insert(8);
?Insert(2);
?Insert(2);
?Insert(3);
?Insert(6);
}
void Insert(UINT32 number)
{
?// 找到一個合適的插入地址
?UINT32 * pBegin =(UINT32 *)g_szBuff;
?UINT32 * pEnd =(UINT32 *)(g_szBuff+g_nCount*SIZE_NODE);
?UINT32 * pInsert =lower_bound(pBegin,pEnd,number);
?if (pInsert != pEnd)
?{
??if (*pInsert == number)
??{
???cout<<"已經有此結點!"<<endl;
???return ;
??}
??memmove(pInsert+1,pInsert,(pEnd-pInsert)*sizeof(UINT32));
?}
?*pInsert=number;
?g_nCount++;
}
void Remove(UINT32 number)
{
?// 找到一個合適的插入地址
?UINT32 * pBegin =(UINT32 *)g_szBuff;
?UINT32 * pEnd =(UINT32 *)(g_szBuff+g_nCount*SIZE_NODE);
?UINT32 * pInsert =lower_bound(pBegin,pEnd,number);
?if (pInsert != pEnd)
?{
??if (*pInsert == number)
??{
???cout<<"已經有此結點!"<<endl;
???return ;
??}
??memmove(pInsert+1,pInsert,(pEnd-pInsert)*sizeof(UINT32));
?}
?g_nCount--;
}
bool Find(UINT32 number)
{
?return true;
}
posted on 2007-01-17 21:34
Sword.Hell blog 閱讀(239)
評論(0) 編輯 收藏 引用 所屬分類:
雜項