头文件
注意点:串的数据类型是用指针查询数据的,注意保护指针不被free掉,长度定义unsigned char 可能小了些。需修改。
/********************************
* FIFO Ready Data Wait Sent*
********************************/
#include <public.hpp>
typedef struct
{
uchar length;
char* Data;
}ReadyplainData;
typedef struct Readyplain
{
Readyplain *next ;
uchar length ;
char* Data;
}Readyplain, * pReadyplain ;
extern ReadyplainData readyplaindata ;
CPP文件:过程:调用函数包含他的头文件后,赋值缓存后创建,及完成。
/*
* regex.hpp
*
* Created on: Jan 5, 2013
* Author: root
*/
typedef struct Ret_Regex
{
char *Data;
unsigned char length;
Ret_Regex *next;
}Ret_Regex,*pRet_Regex ;
#define Linkpointer pRet_Regex
#define LinkEntity Ret_Regex
void Entity_entity(Linkpointer Node)
{
//Node->Data = readyplaindata.length ;
//Node->Data = readyplaindata.Data ;
}
/* first is messy print */
void Entity_print(Linkpointer Node)
{
}
void PrintList(Linkpointer phead)
{
Linkpointer p = phead ;
while(p!=NULL)
{
Entity_print(p);
p = p->next ;
}
}
/* Length 1 no data only head */
int GetLength(Linkpointer phead)
{
Linkpointer p = phead ; int Length=0 ;
while(p!=NULL)
{
Length ++ ;
p = p->next ;
}
return Length ;
}
Linkpointer Before_Null_Node(Linkpointer phead)
{
Linkpointer p = phead ;
while(p->next!=NULL)
{
p=p->next ;
}
return p ;
}
/* Create,return Node add */
Linkpointer CreateNode()
{
Linkpointer pNode = (Linkpointer)malloc(sizeof(LinkEntity));
if(pNode==NULL)
{
printf("Node malloc error \n");
}
Entity_entity(pNode);
pNode->next = NULL ;
return pNode ;
}
/* Add Node between */
void AddNode(Linkpointer pNode,Linkpointer pNode2)
{
Linkpointer pNew = CreateNode();
pNode->next = pNew ;
pNew->next = pNode2 ;
}
/* Delete next Node */
bool DeleteNode(Linkpointer pNode)
{
Linkpointer pDel = pNode->next ;
if(pDel==NULL)
{
printf(" No Node to Delete ");
return 0 ;
}
pNode->next = pDel->next ;
pDel->next = NULL ;
free(pDel);
return 1 ;
}
部分情况修改为使用指针赋值方式更加方便(独立获得位置后赋值)
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
typedef struct Queen_NetData
{
char *Data;
unsigned int length;
Queen_NetData *next;
}Queen_NetData,*pQueen_NetData ;
extern pQueen_NetData pNetData ;
int NetData_Queen_GetLength(pQueen_NetData phead) ;
void NetData_Queen_Entity_entity(pQueen_NetData Node,char* Data);
void NetData_Queen_PrintList(pQueen_NetData phead);
pQueen_NetData NetData_Queen_GetNth_Node(pQueen_NetData phead,int N);
pQueen_NetData NetData_Queen_Before_Null_Node(pQueen_NetData phead);
pQueen_NetData NetData_Queen_CreateNode();
void NetData_Queen_AddNode(pQueen_NetData pNode,pQueen_NetData pNode2);
bool NetData_Queen_DeleteNode(pQueen_NetData pNode);
pQueen_NetData pNetData ;
void NetData_Queen_Entity_entity(pQueen_NetData Node,char* Data)
{
Node->length = strlen(Node->Data);
Node->Data = strdup(Data) ;
printf("NetData_Queen_Data Entitied\n");
}
/* first is messy print */
void NetData_Queen_Entity_print(pQueen_NetData Node)
{
//printf("%s\n",Node->Data);
}
void NetData_Queen_PrintList(pQueen_NetData phead)
{
pQueen_NetData p = phead ;
while(p!=NULL)
{
NetData_Queen_Entity_print(p);
p = p->next ;
}
}
/* Length 1 no data only head */
int NetData_Queen_GetLength(pQueen_NetData phead)
{
pQueen_NetData p = phead ; int Length=0 ;
while(p!=NULL)
{
Length ++ ;
p = p->next ;
}
return Length ;
}
pQueen_NetData NetData_Queen_GetNth_Node(pQueen_NetData phead,int N)
{
if(N==0 || N<0 )
{
return NULL ;
}
else
{
N-=1 ;
pQueen_NetData p = phead ;
while(p->next!=NULL && N>0)
{
p=p->next ;
N-- ;
}
return p ;
}
}
pQueen_NetData NetData_Queen_Before_Null_Node(pQueen_NetData phead)
{
pQueen_NetData p = phead ;
while(p->next!=NULL)
{
p=p->next ;
}
return p ;
}
/* Create,return Node add */
pQueen_NetData NetData_Queen_CreateNode()
{
pQueen_NetData pNode = (pQueen_NetData)malloc(sizeof(Queen_NetData));
if(pNode==NULL)
{
printf("Node malloc error \n");
}
//NetData_Queen_Entity_entity(pNode,Data);
pNode->next = NULL ;
return pNode ;
}
/* Add Node between */
void NetData_Queen_AddNode(pQueen_NetData pNode,pQueen_NetData pNode2)
{
pQueen_NetData pNew = NetData_Queen_CreateNode();
pNode->next = pNew ;
pNew->next = pNode2 ;
}
/* Delete next Node */
bool NetData_Queen_DeleteNode(pQueen_NetData pNode)
{
pQueen_NetData pDel = pNode->next ;
if(pDel==NULL)
{
printf(" No Node to Delete ");
return 0 ;
}
pNode->next = pDel->next ;
pDel->next = NULL ;
//free(pDel->Data);
free(pDel);
return 1 ;
}