Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

[C language data structure] chain stack

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

LinkStack.h

# ifndef LINKSTACK_H#define LINKSTACK_Htypedef void LinkStack;LinkStack* LinkStack_Create (); void LinkStack_Destroy (LinkStack* stack); void LinkStack_Clear (LinkStack* stack); int LinkStack_Push (LinkStack* stack, void* item); void* LinkStack_Pop (LinkStack* stack); void* LinkStack_Top (LinkStack* stack); int LinkStack_Size (LinkStack* stack); # endif / / LINKSTACK_H

LinkStack.c

# include "LinkStack.h" # include "LinkList.h" # include "malloc.h" typedef struct _ tag_LinkStackNode {LinkListNode node; void * item;} TLinkStackNode;LinkStack* LinkStack_Create () {return LinkList_Create ();} void LinkStack_Destroy (LinkStack* stack) {LinkStack_Clear (stack); LinkList_Destroy (stack);} void LinkStack_Clear (LinkStack* stack) {while (LinkStack_Size (stack) > 0) {LinkStack_Pop (stack) }} int LinkStack_Push (LinkStack* stack, void* item) {TLinkStackNode * node = (TLinkStackNode *) malloc (sizeof (TLinkStackNode)); int ret = ((item! = 0) & & (node! = 0)); if (ret) {node- > item = item; ret = LinkList_Insert (stack, (LinkListNode *) node,0);} if (! ret) {free (node);} return ret } void* LinkStack_Pop (LinkStack* stack) {TLinkStackNode * node = (TLinkStackNode *) LinkList_Remove (stack,0); void* ret = 0; if (node! = 0) {ret = node- > item; free (node);} return ret;} void* LinkStack_Top (LinkStack* stack) {TLinkStackNode * node = (TLinkStackNode *) LinkList_Remove (stack,0); void* ret = 0 If (node! = 0) {ret = node- > item;} return ret;} int LinkStack_Size (LinkStack* stack) {return LinkList_Length (stack);}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report