91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

c語言實現的模板,實現方法是使用void指針和size 包括list queue stack三種

資源截圖

代碼片段和文件信息

/**
*?function:?實現鏈表
*?author:?Xiaomu<070105083@163.com>
*?time:?2012-5-19-night
*
*/
#include?“List.h“

#include?
#include?
#include?

/**
*?初始化鏈表
*?@head?鏈表指針
*?@userDataSize?用戶數據大小
*?@return?LIST_OK?for?ok?LIST_ERROR?for?error
*/
int?initList(List?*headint?userDataSize)
{
????if(head==NULL?||?userDataSize<=0)
????????return(LIST_ERROR);

????head->userDataSize=userDataSize;
????head->next=NULL;

????return?LIST_OK;
}
/**
*?在位置pos處插入元素
*?@head?鏈表指針
*?@e?指向新元素指針,該方法會創建新對象保存此指針指向的用戶數據
*?@pos?元素插入位置(0<=pos<=List.length)
*?@return?LIST_OK?for?ok?LIST_ERROR?for?error
*/
int?insertList(List?*headconst?void?*eint?pos)
{
????if(head==NULL?||?e==NULL)
????????return(LIST_ERROR);
????if(pos<0?||?(pos>1?&&?head->next==NULL))
????????return(LIST_ERROR);

????if(pos==0)
????{
????????//在鏈表頭部插入
????????//申請內存空間拷貝用戶數據,以及新的鏈表對象
????????struct?__ListElement?*newElement=(struct?__ListElement*)malloc(sizeof(struct?__ListElement));
????????if(newElement==NULL)
????????????return(LIST_ERROR);
????????newElement->data=malloc(head->userDataSize);
????????if(newElement->data==NULL)
????????{
????????????free(newElement);
????????????return(LIST_ERROR);
????????}
????????if(NULL==memcpy(newElement->dataehead->userDataSize))
????????{
????????????free(newElement->data);
????????????free(newElement);
????????????return(LIST_ERROR);
????????}

????????newElement->next=head->next;
????????head->next=newElement;
????}
????else
????{
????????struct?__ListElement?*pre=head->next?*cur=head->next->next;
????????int?i=1;
????????while(i????????{
????????????pre=cur;
????????????cur=cur->next;
????????????++i;
????????}
????????if(i????????????return(LIST_ERROR);

????????//其他位置插入
????????//申請內存空間拷貝用戶數據,以及新的鏈表對象
????????struct?__ListElement?*newElement=(struct?__ListElement*)malloc(sizeof(struct?__ListElement));
????????if(newElement==NULL)
????????????return(LIST_ERROR);
????????newElement->data=malloc(head->userDataSize);
????????if(newElement->data==NULL)
????????{
????????????free(newElement);
????????????return(LIST_ERROR);
????????}
????????if(NULL==memcpy(newElement->dataehead->userDataSize))
????????{
????????????free(newElement->data);
????????????free(newElement);
????????????return(LIST_ERROR);
????????}

????????newElement->next=cur;
????????pre->next=newElement;
????}

????return(LIST_OK);
}
/**
*?在鏈表結尾插入新元素
*?@head?鏈表指針
*?@e?指向新元素指針,該方法會創建新對象保存此指針指向的用戶數據
*?@return?LIST_OK?for?ok?LIST_ERROR?for?error
*/
int?appendList(List?*headconst?void?*e)
{
????if(head==NULL?||?e==NULL)
????????return(LIST_ERROR);

????//其他位置插入
????//申請內存空間拷貝用戶數據,以及新的鏈表對象
????struct?__ListElement?*newElement=(struct?__ListElement*)malloc(sizeof(struct?__ListElement));
????if(newElement==NULL)
????????return(LIST_ERROR);
????newElement->data=malloc(head->userDataSize);
????if(newElement->data==NULL)
????{
???????

評論

共有 條評論