//////////////////////////////////////// //////////////////////////////////////// //
More original "uC/OS-II Study Notes: Series" Basic and embedded related knowledge details, please visit the cool tiger blog:
Http://blog.csdn.net/dcx1205
I believe it will not disappoint you !! //////////////////////////////////////// //////////////////////////////////////// //
// Write an order stack to encourage everyone! // For more information, see! # Include <stdio. h> # include <math. h> # include <stdlib. h> # define true 1 # define false 0 # define stack_size 5 typedef int elementtype; // defines the struct typedef struct seqstack {elementtype array [stack_size]; elementtype top;} seqstack; // initialize the sequence stack bool initstack (seqstack * PS) {If (! PS) // memory allocation failed {return false;} PS-> Top =-1; return true;} // determines whether bool isempty (seqstack * PS) is empty) {If (PS-> top <0) {return true;} else {return false ;}/// determines whether bool isfull (seqstack * PS) is full) {If (PS-> Top = STACK_SIZE-1) {return true;} else {return false ;}// pressure stack (in stack) bool pushstack (seqstack * ps, elementtype element) {If (isfull (PS) {return false;} PS-> top ++; PS-> array [PS-> top] = element; return true ;} // output stack elementtype popstack (seqstack * PS) {elementtype element; If (isempty (PS) {return false;} element = ps-> array [PS-> top]; PS-> top --; printf ("element = % d \ n", element); Return element;} // obtain the top element of the stack elementtype gettop (seqstack * PS) {elementtype element; If (isempty (PS) {return false;} element = ps-> array [PS-> top]; printf ("element = % d \ n ", element); Return element;} // void setempty (seqstack * PS) {PS-> Top =-1; return ;} // traverse the sequential stack bool trastack (seqstack * PS) {elementtype element; If (isempty (PS) {return false;} while (PS-> top>-1) {element = ps-> array [PS-> top]; PS-> top --; printf ("element = % d \ n", element);} return true ;} // main function int main (void) {seqstack * pS; // defines a pointer to the struct variable PS = (seqstack *) malloc (sizeof (seqstack )); // The following function parameters use P and & PS as the equivalent initstack (PS); // initialize pushstack (Ps, 1); // press the stack pushstack (Ps, 2 ); pushstack (Ps, 3); pushstack (Ps, 4); pushstack (Ps, 5); gettop (PS); // obtain the top element of the stack printf ("\ n "); popstack (PS); // printf ("\ n"); trastack (PS); // traverse the stack free (PS ); // release the memory space occupied by PS. Return 0 ;}