标签:style blog color io os ar for 数据 div
/******************************************************************** @file Main_practise.cpp @date 2014-9-25 @author Tiger @brief 数据结构 @details 堆栈 ********************************************************************/ #include <iostream> #define STACK_SIZE 5 typedef int ElementType; typedef struct { ElementType m_Data[STACK_SIZE]; int m_nTop; }STACK, *PSTACK; void initStack(PSTACK pMyStack) { pMyStack->m_nTop = -1; } bool isEmpty(PSTACK pMyStack) { return pMyStack->m_nTop == -1; } bool isFull(PSTACK pMyStack) { return pMyStack->m_nTop == STACK_SIZE-1; } bool push(PSTACK pMyStack, ElementType elem) { if (isFull(pMyStack)) return false; pMyStack->m_Data[++pMyStack->m_nTop] = elem; return true; } bool pop(PSTACK pMyStack, ElementType& elem) { if (isEmpty(pMyStack)) return false; elem = pMyStack->m_Data[pMyStack->m_nTop--]; return true; } bool getTop(PSTACK pMyStack, ElementType& elem) { if (isEmpty(pMyStack)) return false; elem = pMyStack->m_Data[pMyStack->m_nTop]; return true; } int main(int argc, const char* argv[]) { PSTACK pMyStack = new STACK; initStack(pMyStack); for (int i=0; i<STACK_SIZE; ++i) { push(pMyStack, i); } while (!isEmpty(pMyStack)) { ElementType elem = 0; pop(pMyStack, elem); std::cout << elem << std::endl; } delete pMyStack; return 0; }
标签:style blog color io os ar for 数据 div
原文地址:http://www.cnblogs.com/roronoa-zoro-zrh/p/3992579.html