c语言实现动态指针数组Dynamic arrays
c语言实现动态数组。其它c的数据结构实现,hashTable參考点击打开链接 treeStruct參考点击打开链接
基本原理:事先准备好一个固定长度的数组。
假设长度不够的时候。realloc一块区域。
另外:在数组元素降低的情况下。须要缩减数组长度。
主要接口:
- cp_bool DyArrayAppend(DyArray* pArr, void* pData)//加数据到数组末尾
- cp_bool DyArrayExpand(DyArray* pArr, cp_int32 nNeed)//扩展数组
- cp_bool DyArrayDelete(DyArray* pArr, cp_int32 nIndex)//删除元素by index
- cp_bool DyArrayShrink(DyArray* pArr)//缩减数组
源码例如以下:(iOS平台的c实现)
- //
- // dyArray.h
- // dataStruct
- //
- // Created by hherima on 14-7-28.
- // Copyright (c) 2014年 . All rights reserved.
- //
- #ifndef dataStruct_dyArray_h
- #define dataStruct_dyArray_h
- #include <stdlib.h>
- enum
- {
- CP_FALSE = 0,
- CP_TRUE = !CP_FALSE
- };
- typedef unsigned char cp_bool;
- typedef signed int cp_int32;
- typedef void (*DataDestroyFunc)(void *);
- typedef cp_bool (*DataCmpFunc)(void *,void *);
- typedef void (*DataVisitFunc)(void *);
- #define F_MALLOC_TYPE(s) (s*)f_malloc(sizeof(s))
- #define FREEFUN free
- #define MIN_PRE_ALLOCATE_SIZE 10 //The initial size of the dynamic array.
- #define MEMSETFUN memset
- #define REALLOCFUN realloc
- #define MALLOCFUN malloc
- struct DynamicArray
- {
- void **m_ppData; //the address of the allocated array.
- cp_int32 m_nAllocSize; //the allocated array size.
- cp_int32 m_nSize; //the used size of the array.
- DataDestroyFunc m_fDestroy; //the callback function to destroy one data.
- DataCmpFunc m_fCmp; //the callback function to compare one data.
- DataVisitFunc m_fVisit; //the callback function to visit each data.
- };
- typedef struct DynamicArray DyArray;
- DyArray* DyArrayCreate(DataDestroyFunc pDataDestroy);
- cp_bool DyArrayInsert(DyArray* pArr, cp_int32 nIndex, void* pData);
- cp_bool DyArrayPrepend(DyArray* pArr, void* pData);
- cp_bool DyArrayAppend(DyArray* pArr, void* pData);
- cp_bool DyArrayDelete(DyArray* pArr, cp_int32 nIndex);
- cp_bool DyArrayDeleteEx(DyArray* pArr, cp_int32 nBegin,cp_int32 nEnd);
- cp_bool DyArrayGetByIndex(DyArray* pArr, cp_int32 nIndex, void** ppData);
- cp_bool DyArrayGetFirst(DyArray* pArr,void** ppData);
- cp_bool DyArrayGetLast(DyArray* pArr,void** ppData);
- cp_bool DyArraySetByIndex(DyArray* pArr, cp_int32 nIndex, void* pData);
- cp_int32 DyArrayLength(DyArray* pArr);
- cp_int32 DyArrayFind(DyArray* pArr, DataCmpFunc pCmp,void *pData);
- cp_bool DyArrayForEach(DyArray* pArr, DataVisitFunc pVisit);
- void DyArrayDestroy(DyArray* pArr);
- void DyArrayDestroyCustom(DyArray* pArr,DataDestroyFunc pDataDestroy);
- void DyArrayReset(DyArray* pArr);//shrink
- void DyArrayClear(DyArray* pArr);//not shrink
- void DyArrayResetCustom(DyArray* pArr,DataDestroyFunc pDataDestroy);
- void DyArrayClearCustom(DyArray* pArr,DataDestroyFunc pDataDestroy);//not shrink
- #endif
- //
- // dyArray.c
- // dataStruct
- //
- // Created by hherima on 14-7-28.
- // Copyright (c) 2014年 . All rights reserved.
- //
- #include "dyArray.h"
- void* f_malloc(cp_int32 size)
- {
- void* p = MALLOCFUN(size);
- if(p)
- MEMSETFUN(p, 0, size);
- return p;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayCreate
- 【描写叙述】: 创建长度为MIN_PRE_ALLOCATE_SIZE的动态指针数组
- 【參数】:
- pDataDestroy: the callback function to destroy one data in data array.
- 【返回值】: 动态指针数组的地址
- ***************************************************************************************************/
- DyArray* DyArrayCreate(DataDestroyFunc pDataDestroy)
- {
- DyArray *pArr = NULL;
- pArr = F_MALLOC_TYPE(DyArray);
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return NULL;
- }
- //malloc memory for dynamic array and iniatilize it.
- pArr->m_fDestroy = pDataDestroy;
- pArr->m_ppData = (void *)f_malloc(sizeof(void *)*MIN_PRE_ALLOCATE_SIZE);
- if(!pArr->m_ppData)
- {
- FREEFUN(pArr);
- return NULL;
- }
- pArr->m_nAllocSize = MIN_PRE_ALLOCATE_SIZE;
- return pArr;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayGetByIndex
- 【描写叙述】:获取数组元素by index
- 【參数】:
- pArr: the array's address.
- nIndex: the element's position.
- ppData: out parameter, to record the element's pointer.
- 【返回值】: true or false.
- ***************************************************************************************************/
- cp_bool DyArrayGetByIndex(DyArray* pArr, cp_int32 nIndex, void** ppData)
- {
- //if the input parameter is invalid, return.
- if(!pArr || nIndex < 0 || !ppData || nIndex >= pArr->m_nSize)
- {
- *ppData = NULL;
- return CP_FALSE;
- }
- *ppData = pArr->m_ppData[nIndex];//get the related element.
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayGetFirst
- 【描写叙述】:获取数组第一个元素
- 【參数】:
- pArr: the array's address.
- ppData: out parameter, to record the element's pointer.
- 【返回值】: true or false.
- ***************************************************************************************************/
- cp_bool DyArrayGetFirst(DyArray* pArr,void** ppData)
- {
- return DyArrayGetByIndex(pArr,0,ppData) ?
- CP_TRUE : CP_FALSE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayGetLast
- 【描写叙述】: 获取数组最后一个元素
- 【參数】:
- pArr: the array's address.
- ppData: out parameter, to record the element's pointer.
- 【返回值】: true or false.
- ***************************************************************************************************/
- cp_bool DyArrayGetLast(DyArray* pArr,void** ppData)
- {
- return DyArrayGetByIndex(pArr,pArr->m_nSize-1,ppData) ? CP_TRUE : CP_FALSE;
- }
- /**************************************************************************************************
- 【函数名】:DyArraySetByIndex
- 【描写叙述】: 设置数组元素by index
- 【參数】:
- pArr: the array's address.
- nIndex: the element's position.
- pData: the element's pointer.
- 【返回值】: true or false.
- ***************************************************************************************************/
- cp_bool DyArraySetByIndex(DyArray* pArr, cp_int32 nIndex, void* pData)
- {
- //if the input parameter is invalid, return.
- if(!pArr || nIndex < 0)
- {
- return CP_FALSE;
- }
- pArr->m_ppData[nIndex] = pData;//find the related position and set its value.
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayLength
- 【描写叙述】:获取数组的长度
- 【參数】:
- pArr: the array's address.
- 【返回值】: 数组长度.
- ***************************************************************************************************/
- cp_int32 DyArrayLength(DyArray* pArr)
- {
- return pArr ? pArr->m_nSize : -1;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayFind
- 【描写叙述】:查找数组中的指定元素
- 【參数】:
- pArr: the array's address.
- pCmp: the callback function to compare the data.
- pData: the search destination in the array.
- 【返回值】:假设成功返回位置,否则返回-1
- ***************************************************************************************************/
- cp_int32 DyArrayFind(DyArray* pArr, DataCmpFunc pCmp,void *pData)
- {
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return -1;
- }
- //visit each one to find the right one.
- for(i=0; i<pArr->m_nSize;i++)
- {
- if(pCmp)
- {
- if(pCmp(pArr->m_ppData[i],pData) == CP_TRUE)
- {
- return i;
- }
- }else
- {
- //if NO compare funciton, just compare the address.
- if(pArr->m_ppData[i] == pData)
- {
- return i;
- }
- }
- }
- return -1;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayForEach
- 【描写叙述】:遍历数组
- 【參数】:
- pArr: the array's address.
- pVisit: the callback function to visit the data.
- 【返回值】:假设成功返回true,否则false
- ***************************************************************************************************/
- cp_bool DyArrayForEach(DyArray* pArr, DataVisitFunc pVisit)
- {
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr || !pVisit)
- {
- return CP_FALSE;
- }
- //visit each one with the visit function.
- for(i=0; i<pArr->m_nSize;i++)
- {
- pVisit(pArr->m_ppData[i]);
- }
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayDestroy
- 【描写叙述】:销毁整个数组
- 【參数】:
- pArr: the array's address.
- 【返回值】:NA
- ***************************************************************************************************/
- void DyArrayDestroy(DyArray* pArr)
- {
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //Using destroy function to destroy each element's memory.
- if(pArr->m_fDestroy)
- {
- for(i=0; i<pArr->m_nSize; i++)
- {
- pArr->m_fDestroy(pArr->m_ppData[i]);
- }
- }
- //free the array.
- FREEFUN(pArr->m_ppData);
- pArr->m_ppData = NULL;
- FREEFUN(pArr);
- pArr = NULL;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayDestroyCustom
- 【描写叙述】:使用用户函数。小围数组
- 【參数】:
- pArr: the array's address.
- pDataDestroy: user's destroy function.
- 【返回值】:NA
- ***************************************************************************************************/
- void DyArrayDestroyCustom(DyArray* pArr,DataDestroyFunc pDataDestroy)
- {
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //Using destroy function to destroy each element's memory.
- if(pDataDestroy)
- {
- for(i=0; i<pArr->m_nSize;i++)
- {
- pDataDestroy(pArr->m_ppData[i]);
- }
- }
- //free the array.
- FREEFUN(pArr->m_ppData);
- pArr->m_ppData = NULL;
- FREEFUN(pArr);
- }
- /**************************************************************************************************
- 【函数名】: DyArrayExpand
- 【描写叙述】:扩展数组
- 【參数】:
- pArr: the array's address.
- nNeed: the needed new size.
- 【返回值】:假设成功返回ture否则返回false
- ***************************************************************************************************/
- cp_bool DyArrayExpand(DyArray* pArr, cp_int32 nNeed)
- {
- cp_int32 allocSize = 0;
- void** data = NULL;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return CP_FALSE;
- }
- //if need, expand to 1.5 times of the original size.
- if((pArr->m_nSize + nNeed) > pArr->m_nAllocSize)
- {
- allocSize = pArr->m_nAllocSize + (pArr->m_nAllocSize>>1);
- data = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * allocSize);
- if(data != NULL)
- {
- //clear the expanded space of the new memory.
- MEMSETFUN(data+pArr->m_nAllocSize,0,(allocSize-pArr->m_nAllocSize)*sizeof(void*));
- pArr->m_ppData = data;
- pArr->m_nAllocSize = allocSize;
- }
- }
- return ((pArr->m_nSize + nNeed) <= pArr->m_nAllocSize) ? CP_TRUE : CP_FALSE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayInsert
- 【描写叙述】:插入数组by index
- 【參数】:
- pArr: the array's address.
- nIndex: the position in the array to insert new data.
- pData: the data to be inserted.
- 【返回值】:假设成功返回true否则false
- ***************************************************************************************************/
- cp_bool DyArrayInsert(DyArray* pArr, cp_int32 nIndex, void* pData)
- {
- cp_bool bRet = CP_FALSE;
- cp_int32 nCursor = nIndex;
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return CP_FALSE;
- }
- //get the right cursor.
- nCursor = nCursor < pArr->m_nSize ? nCursor : pArr->m_nSize;
- if(DyArrayExpand(pArr, 1) == CP_TRUE)
- {
- //move all the elements after the cursor to the next positon.
- for(i = pArr->m_nSize; i > nCursor; i--)
- {
- pArr->m_ppData[i] = pArr->m_ppData[i-1];
- }
- //set the cursor's value.
- pArr->m_ppData[nCursor] = pData;
- pArr->m_nSize++;
- bRet = CP_TRUE;
- }
- return bRet;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayPrepend
- 【描写叙述】:在数组開始加入一个数据
- 【參数】:
- pArr: the array's address.
- pData: the data to be added.
- 【返回值】:假设成功返回ture,否则false
- ***************************************************************************************************/
- cp_bool DyArrayPrepend(DyArray* pArr, void* pData)
- {
- return DyArrayInsert(pArr,0,pData) ? CP_TRUE:CP_FALSE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayAppend
- 【描写叙述】:加入数据到数组末尾
- 【參数】:
- pArr: the array's address.
- pData: the data to be added.
- 【返回值】:假设成功返回true。否则false
- ***************************************************************************************************/
- cp_bool DyArrayAppend(DyArray* pArr, void* pData)
- {
- return DyArrayInsert(pArr,pArr->m_nSize,pData) ?
- CP_TRUE:CP_FALSE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayShrink
- 【描写叙述】:缩减数组
- 【參数】:
- pArr: the array's address.
- 【返回值】:ture 或者false
- ***************************************************************************************************/
- cp_bool DyArrayShrink(DyArray* pArr)
- {
- cp_int32 nAllocSize = 0;
- void** pData = NULL;
- //if the input 【參数】 is invalid, return.
- if(!pArr)
- {
- return CP_FALSE;
- }
- //if need, shrink the array to 1.5 times of elements number.
- if((pArr->m_nSize < (pArr->m_nAllocSize >> 1)) && (pArr->m_nAllocSize > MIN_PRE_ALLOCATE_SIZE))
- {
- nAllocSize = pArr->m_nSize + (pArr->m_nSize >> 1);
- pData = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * nAllocSize);
- if(pData != NULL)
- {
- //clear memory of the unused space of new memory.
- MEMSETFUN(pData+pArr->m_nSize,0,(nAllocSize-pArr->m_nSize)*sizeof(void*));
- pArr->m_ppData = pData;
- pArr->m_nAllocSize = nAllocSize;
- }
- }
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayDelete
- 【描写叙述】:删除元素by index
- 【參数】:
- pArr: the array's address.
- nIndex: the position in the array to delete useless data.
- 【返回值】:ture 或者false
- ***************************************************************************************************/
- cp_bool DyArrayDelete(DyArray* pArr, cp_int32 nIndex)
- {
- cp_int32 i;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return CP_FALSE;
- }
- //destroy the element with destroy function.
- if(pArr->m_fDestroy)
- {
- pArr->m_fDestroy(pArr->m_ppData[nIndex]);
- }
- //move the elements after 'nIndex' to the previous one.
- for(i = nIndex; (i+1) < pArr->m_nSize; i++)
- {
- pArr->m_ppData[i] = pArr->m_ppData[i+1];
- }
- //set the last one to null.
- pArr->m_ppData[i] = NULL;
- pArr->m_nSize--;
- //if need ,shrink the size.
- DyArrayShrink(pArr);
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayDeleteEx
- 【描写叙述】:删除元素by index (扩展)
- 【參数】:
- pArr: the array's address.
- nIndex: the position in the array to delete useless data.
- nEdn:
- 【返回值】:ture 或者false
- ***************************************************************************************************/
- cp_bool DyArrayDeleteEx(DyArray* pArr, cp_int32 nBegin,cp_int32 nEnd)
- {
- cp_int32 i,nLen = 0;
- //if the input parameter is invalid, return.
- //if(!pArr && nBegin>nEnd && nBegin<0 && nBegin>=pArr->m_nSize && nEnd<0 && nEnd>=pArr->m_nSize)
- if(!pArr)
- {
- return CP_FALSE;
- }
- //destroy the element with destroy function.
- if(pArr->m_fDestroy)
- {
- for(i=nBegin; i<=nEnd; i++)
- {
- pArr->m_fDestroy(pArr->m_ppData[i]);
- }
- }
- //move the elements after 'nIndex' to the previous one.
- nLen = nEnd - nBegin + 1;
- for(i = nBegin; (i+nLen) < pArr->m_nSize; i++)
- {
- pArr->m_ppData[i] = pArr->m_ppData[i+nLen];
- }
- //set the last one to null.
- //pArr->m_ppData[i] = NULL;
- pArr->m_nSize -= nLen;
- //if need ,shrink the size.
- DyArrayShrink(pArr);
- return CP_TRUE;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayReset
- 【描写叙述】:清除数组数据,缩减数组到原始大小
- 【參数】:
- pArr: the array's address.
- 【返回值】:
- none.
- ***************************************************************************************************/
- void DyArrayReset(DyArray* pArr)
- {
- cp_int32 i;
- void** pData = NULL;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //reset all the elements with destroy function.
- if(pArr->m_fDestroy)
- {
- for(i=0; i<pArr->m_nSize;i++)
- {
- pArr->m_fDestroy(pArr->m_ppData[i]);
- }
- }
- pArr->m_nSize = 0;
- //if need, shrink the size.
- if(pArr->m_nAllocSize > MIN_PRE_ALLOCATE_SIZE)
- {
- pData = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * MIN_PRE_ALLOCATE_SIZE);
- if(pData != NULL)
- {
- pArr->m_ppData = pData;
- pArr->m_nAllocSize = MIN_PRE_ALLOCATE_SIZE;
- }
- if(pArr->m_ppData)
- {
- MEMSETFUN(pArr->m_ppData,0,sizeof(void*)*pArr->m_nAllocSize);
- }
- }
- }
- /**************************************************************************************************
- 【函数名】: DyArrayClear
- 【描写叙述】:清除数组数据。不缩减数组到原始大小
- 【參数】:
- pArr: the array's address.
- 【返回值】:NA
- ***************************************************************************************************/
- void DyArrayClear(DyArray* pArr)
- {
- cp_int32 i;
- void** pData = NULL;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //reset all the elements with destroy function.
- if(pArr->m_fDestroy)
- {
- for(i=0; i<pArr->m_nSize;i++)
- {
- pArr->m_fDestroy(pArr->m_ppData[i]);
- }
- }
- pArr->m_nSize = 0;
- }
- /**************************************************************************************************
- 【函数名】: DyArrayResetCustom
- 【描写叙述】:清除数组使用用户函数,缩减数组到原始大小
- 【參数】:
- pArr: the array's address.
- pDataDestroy: user's destroy function.
- 【返回值】:NA
- ***************************************************************************************************/
- void DyArrayResetCustom(DyArray* pArr,DataDestroyFunc pDataDestroy)
- {
- cp_int32 i;
- void** pData = NULL;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //reset all the elements with destroy function.
- if(pDataDestroy)
- {
- for(i=0; i<pArr->m_nSize;i++)
- {
- pDataDestroy(pArr->m_ppData[i]);
- }
- }
- pArr->m_nSize = 0;
- //if need, shrink the size.
- if(pArr->m_nAllocSize > MIN_PRE_ALLOCATE_SIZE)
- {
- pData = (void**)REALLOCFUN(pArr->m_ppData, sizeof(void*) * MIN_PRE_ALLOCATE_SIZE);
- if(pData != NULL)
- {
- pArr->m_ppData = pData;
- pArr->m_nAllocSize = MIN_PRE_ALLOCATE_SIZE;
- }
- if(pArr->m_ppData)
- {
- MEMSETFUN(pArr->m_ppData,0,sizeof(void*)*pArr->m_nAllocSize);
- }
- }
- }
- /**************************************************************************************************
- 【函数名】: DyArrayClearCustom
- 【描写叙述】:清除数组使用用户函数,不缩减数组到原始大小
- 【參数】:
- pArr: the array's address.
- pDataDestroy: user's destroy function.
- 【返回值】:NA
- ***************************************************************************************************/
- void DyArrayClearCustom(DyArray* pArr,DataDestroyFunc pDataDestroy)
- {
- cp_int32 i;
- void** pData = NULL;
- //if the input parameter is invalid, return.
- if(!pArr)
- {
- return;
- }
- //reset all the elements with destroy function.
- if(pDataDestroy)
- {
- for(i=0; i<pArr->m_nSize;i++)
- {
- pDataDestroy(pArr->m_ppData[i]);
- }
- }
- pArr->m_nSize = 0;
- }
c语言实现动态指针数组Dynamic arrays的更多相关文章
- C语言中的指针数组
C语言中的指针数组是什么,像 char *a[]={"ddd","dsidd","lll"}; 这里讲一下注意如果我们使用了a也就是首元素的 ...
- C语言中的指针数组和数组指针
代码: #include <iostream> using namespace std; int main(){ ]; ]; cout<<sizeof(a)<<en ...
- C语言的函数指针数组(好绕啊~看完这篇估计就通关了)
转自https://www.cnblogs.com/chr-wonder/p/5168858.html int *(*p(int))[3] 今天有人问这个是啥?我一看直接就懵逼了…… 下面做一些简单的 ...
- C语言深度剖析-----指针数组和数组指针的分析
指针数组和数组指针的分析 数组类型 定义数组类型 数组指针 这个不可能为数组指针,指向数组首元素 例 指针数组 例 main函数的参数 例 小结
- 嵌入式-C语言基础:指针数组(和数组指针区分开来)
指针数组:一个数组,若其元素均为指针类型的数据,称为指针数组,指针数组存放的是指针类型的数据,也就是指针数组的每个元素都存放一个地址.下面定义一个指针数组: int * p[4];//[]的优先级是比 ...
- C#委托与C语言函数指针及函数指针数组
C#委托与C语言函数指针及函数指针数组 在使用C#时总会为委托而感到疑惑,但现在总新温习了一遍C语言后,才真正理解的委托. 其实委托就类似于C/C++里的函数指针,在函数传参时传递的是函数指针,在调用 ...
- C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | IT宅.com
原文:C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | IT宅.com C语言语法笔记 – 高级用法 指针数组 指针的指针 二维数组指针 结构体指针 链表 | I ...
- 【嵌入式开发】C语言 内存分配 地址 指针 数组 参数 实例解析
. Android源码看的鸭梨大啊, 补一下C语言基础 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/detai ...
- 数据结构基础(1)--数组C语言实现--动态内存分配
数据结构基础(1)--数组C语言实现--动态内存分配 基本思想:数组是最常用的数据结构,在内存中连续存储,可以静态初始化(int a[2]={1,2}),可以动态初始化 malloc(). 难点就是数 ...
随机推荐
- 通过xml生成word文档
Xml生成word总结 使用xml生成word的基本步骤在<使用xslt转化xml数据形成word文档导出.doc>中说明比较清楚了.但是其中的细节并未说到,因此自己折腾了两天总算成功了. ...
- Android 设备管理器 阻止用户取消激活
该方案测试可行,系统版本4.4.2.它算是借助android系统的一个bug,不确定在后续更高的版本中是否修复. 该功能和360防卸载功能一样的实现原理. 主要的参考资料是:http://bbs.pe ...
- linux系统文件属性-硬连接、软连接
1 硬链接概念 硬链接是指通过索引节点(Inode)来进行链接,在Linux(ext2,ext3)文件系统中,保存在磁盘分区中的文件不管是什么类型都会给它分配一个编号,这个编号被称为索引节点编号(In ...
- Android 程式开发:(二十)内容提供者 —— 20.6 自定义ContentProvider的使用
现在,ContentProvider已经创建好了,可以去尝试使用一下. 1. 使用之前的工程,在布局文件main.xml中添加一些控件. <?xml version="1.0" ...
- 怎样用HTML5 Canvas制作一个简单的游戏
原文连接: How To Make A Simple HTML5 Canvas Game 自从我制作了一些HTML5游戏(例如Crypt Run)后,我收到了很多建议,要求我写一篇关于怎样利用HTML ...
- HDU-1664-Different Digits(BFS)
Problem Description Given a positive integer n, your task is to find a positive integer m, which is ...
- javascript笔记整理(window对象)
浏览器对象模型 (BOM--Browser Object Model),window对象是BOM中所有对象的核心 A.属性 1.(位置类型-获得浏览器的位置) IE:window.screenLeft ...
- 修改OpenSSL默认编译出的动态库文件名称
在 Windows 平台上调用动态链接库 dll 文件时,有两种方式:a) 隐式的加载时链接:使用 *.lib (导入库)文件,在 IDE 的链接器相关设置中加入导入库 lib 文件的名称,或在程序中 ...
- Spring MVC 遇到的一点点问题(转)
今天下午下班之前看了看凯歌给的Spring Training的教程的lab篇,我之前有跟着做没有遇到什么问题,但是到了跟Spring MVC integrating的时候,遇到一点点有趣的事情. 这个 ...
- Swift - 正则表达式的使用(附用户名、邮箱、URL等常用格式验证)
Swift虽然是一个新出的语言,但却不提供专门的处理正则的语法和类.所以我们只能使用古老的NSRegularExpression类进行正则匹配. 即先接受一个正则表达式的字符串,由此生成NSRegul ...