在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!) 创芯人才网--重磅上线啦!
查看: 2789|回复: 0

[原创] 链表应用

[复制链接]
发表于 2011-7-7 16:35:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
typedef struct STRUCTMENUINFO
{
unsigned int uTab;//号
char MenuName[64];//名字
float fDyj;//单价
float fNum;//数量
float fZdyj;//总价
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))
  {
   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);
  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 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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-22 08:22 , Processed in 0.014704 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表