|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
#include <stdio.h>
#include <stdlib.h>
typedef struct STRUCTMENUINFO
{
unsigned int uTab;//号
char MenuName[64];//名字
float fDyj;//单价
float fNum;//数量
float fZdyj;//总价
bool Flag;//标志
struct STRUCTMENUINFO *Node;//节点存储
} stMenuInfo;
int PrintMenuInfoFun(stMenuInfo *pstRootNode,unsigned int uTab)
{
stMenuInfo *pstRootNodeTmp = 0ul;
if ((0ul == pstRootNode) || (0 == uTab))
{
printf("Print Info Fun Null!");
return ~(0);
}
pstRootNodeTmp = pstRootNode;
while(pstRootNodeTmp->Node != 0ul)
{
pstRootNodeTmp = pstRootNodeTmp->Node;
if (pstRootNodeTmp->uTab == uTab)
{
printf("Name:%s\n", pstRootNodeTmp->MenuName);
printf("dj:%f\n", pstRootNodeTmp->fDyj);
printf("num:%f\n", pstRootNodeTmp->fNum);
printf("zdj:%f\n", pstRootNodeTmp->fZdyj);
printf("Tab:%d\n", pstRootNodeTmp->uTab);
}
}
return 0;
}
int PrintNameFun(stMenuInfo *pstRootNode,char *Name)
{
stMenuInfo *pstRootNodeTmp = 0ul;
if ((0ul == pstRootNode) || (0ul == Name))
{
printf("Print Info Fun Null!");
return ~(0);
}
pstRootNodeTmp = pstRootNode;
while(pstRootNodeTmp->Node != 0ul)
{
pstRootNodeTmp = pstRootNodeTmp->Node;
if (!strncmp(pstRootNodeTmp->MenuName, Name, sizeof(Name)))
{
printf("Name:%s\n", pstRootNodeTmp->MenuName);
printf("dj:%f\n", pstRootNodeTmp->fDyj);
printf("num:%f\n", pstRootNodeTmp->fNum);
printf("zdj:%f\n", pstRootNodeTmp->fZdyj);
printf("Tab:%d\n", pstRootNodeTmp->uTab);
}
}
return 0;
}
int AddMenuInfoFun(stMenuInfo *pstRootNode, unsigned int uTab, char *Name, float fNum, float fDyj)
{
stMenuInfo *pstRootNodeTmp = 0ul;
stMenuInfo *pstNodeInfo = 0ul;
stMenuInfo *pstNewNode = 0ul;
if ((0ul == pstRootNode) || (0ul == Name) || (0 == uTab))
{
printf("Fun Info Data to Null!");
return ~(0);
}
pstRootNodeTmp = pstRootNode;
while(pstRootNodeTmp->Node != 0ul)
{
pstRootNodeTmp = pstRootNodeTmp->Node;
}
if (pstRootNodeTmp->Node == 0ul)
{
pstNewNode = (stMenuInfo *)malloc(sizeof(stMenuInfo));
pstNewNode->Node = 0ul;
pstNewNode->uTab = uTab;
strcpy(pstNewNode->MenuName, Name);
pstNewNode->fDyj = fDyj;
pstNewNode->fNum = fNum;
pstNewNode->fZdyj = (fDyj * fNum);
pstNewNode->Flag = 1;
pstRootNodeTmp->Node = pstNewNode;
}
return 0;
}
int DelMenuInfoFun(stMenuInfo *pstRootNode, unsigned int uTab)
{
stMenuInfo *pstRootNodeTmp = 0ul;
stMenuInfo *pstNextRootNode = 0ul;
if ((0ul == pstRootNode) || (0 == uTab))
{
printf("Print Info Fun Null!");
return ~(0);
}
pstRootNodeTmp = pstRootNode;
while(pstRootNodeTmp->Node != 0ul)
{
pstNextRootNode = pstRootNodeTmp;
pstRootNodeTmp = pstRootNodeTmp->Node;
if (pstRootNodeTmp->uTab == uTab)
{
pstNextRootNode->Node = pstRootNodeTmp->Node;
}
}
return 0;
}
int DelTabMenuInfoFun(stMenuInfo *pstRootNode, unsigned int uTab, char *Name)
{
stMenuInfo *pstRootNodeTmp = 0ul;
stMenuInfo *pstNextRootNode = 0ul;
if ((0ul == pstRootNode) || (0 == uTab))
{
printf("Print Info Fun Null!");
return ~(0);
}
pstRootNodeTmp = pstRootNode;
while(pstRootNodeTmp->Node != 0ul)
{
pstNextRootNode = pstRootNodeTmp;
pstRootNodeTmp = pstRootNodeTmp->Node;
if (pstRootNodeTmp->uTab == uTab)
{
if (!strncmp(pstRootNodeTmp->MenuName , Name, sizeof(Name)))
{
pstNextRootNode->Flag = 0;
}
}
}
return 0;
}
int main()
{
stMenuInfo *RootNode = (stMenuInfo *)malloc(sizeof(stMenuInfo));
RootNode->Node = 0ul;
AddMenuInfoFun(RootNode, 2, "快问问", 3.0, 2.5);
AddMenuInfoFun(RootNode, 3, "快", 5, 2);
AddMenuInfoFun(RootNode, 2, "问", 3, 1);
AddMenuInfoFun(RootNode, 4, "课文", 1, 1.5);
AddMenuInfoFun(RootNode, 3, "英语", 7, 3);
PrintMenuInfoFun(RootNode, 2);
PrintNameFun(RootNode, "课文");
DelMenuInfoFun(RootNode, 2);
PrintMenuInfoFun(RootNode, 2);
PrintMenuInfoFun(RootNode, 3);
while(1);
return 0;
} |
|