stack link
来源:互联网 发布:mac装好windows没wifi 编辑:程序博客网 时间:2024/06/08 19:42
CODE
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>typedef struct tagStackNode{int iValue;struct tagStackNode *pstNext;}STACK_NODE_S;static STACK_NODE_S *pstStack;#define STACK_TOP() \pstStack;#define STACK_SET_TOP(pstTop) \{ \pstStack = pstTop; \}int STACK_Push(int iNum){int iRet = -1;STACK_NODE_S *pstTop;pstTop = (STACK_NODE_S *)malloc(sizeof(STACK_NODE_S));if (pstTop != NULL){memset(pstTop, 0, sizeof(STACK_NODE_S));pstTop->iValue = iNum;pstTop->pstNext = STACK_TOP();STACK_SET_TOP(pstTop);iRet = 0;}return iRet;}void STACK_Pop(){STACK_NODE_S *pstCurTop = NULL;pstCurTop = STACK_TOP();assert(pstCurTop != NULL);STACK_SET_TOP(pstCurTop->pstNext);free(pstCurTop);return;}int STACK_Top(){STACK_NODE_S *pstTop;pstTop = STACK_TOP();assert(pstTop != NULL);return pstTop->iValue;}int STACK_IsEmpty(){STACK_NODE_S *pstTop;pstTop = STACK_TOP();return pstTop == NULL;}int main(){int iRet = -1;int i;STACK_NODE_S *pstTop;printf("Push:\r\n");for (i = 0; i < 5; i++){iRet = rand();printf("%d ", iRet);STACK_Push(iRet);}printf("\r\n");printf("Display and Pop.\r\n");while (STACK_IsEmpty() == 0){printf("%d ", STACK_Top());STACK_Pop();}return iRet;}
Result
Push:
1804289383 846930886 1681692777 1714636915 1957747793
Display and Pop.
1957747793 1714636915 1681692777 846930886 1804289383
0 0
- Link Stack
- stack link
- 链栈 Link Stack
- 链栈(link stack)
- Stack----use database and link
- (2011.07.20) 链式栈 // Link list-based stack implementation
- Stack(栈)和Heap(堆)Link Node 小结
- 汇编link时提示no stack segment 解决
- <汇编>MASM5.0编译出现<error link:no stack segment>
- link
- link
- link
- LINK
- link
- link
- link
- Link
- link
- C_HelloLinux
- githubz在add ssh key报错 Key is invalid. Ensure you've copied the file correctly 解决办法
- 注解
- Java线程范围内的共享数据(2)
- SAP连接数据库
- stack link
- Codility上的练习(12)
- 关于开源框架GPUImage 的简单说明
- VB中With
- NSAutoreleasePool与autorelease 详解(一)
- Git常用基础命令总结
- UVa 10763 - Foreign Exchange
- [学习笔记]Java多态性
- iOS UserInterfaceState.xcuserstate文件在Git版本控制中不能忽略