1 //sequential stack. CPP: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"//test1.0--Stack Table limited to int type5#include <stdio.h>6 7 #defineTrue 18 #defineFalse 09 TentypedefstructStack_type One { A intstack[ -];//maximum of 100 elements - inttop; - }stacktype; the - intPushes (Stacktype *s,intx);//Press-in stack - intPOPs (Stacktype *s);//Delete Stack - voidInitiatest (Stacktype *s);//Initialize + - intMainvoid) + { A Stacktype L; atStacktype *sta = &L;//failed, if there is no l this element, directly Stacktype *sta, the compiler will report "uninitialized local variable" STA "" - intI, x,m; - - initiatest (STA); - -i =0; in - for(;; i++) to { +scanf_s ("%d", &x); - the if(x = =-2) * { $ Break;Panax Notoginseng } - the pushes (STA, x); + } A the for(M =0; M < i; m++) + { -printf_s ("%d", sta->stack[m]); $ } $ - return 0; - } the - intPushes (Stacktype *s,intx)Wuyi { the if(S->top >= About) - { Wu return(false); - } About Else $ { -s->top++; -S->stack[s->top] =x; - return(true); A } + } the - intPOPs (Stacktype *s) $ { the if(S->top <0) the { the return(false); the } - Else in { thes->top--; the return(S->stack[s->top +1]); About } the } the the voidInitiatest (Stacktype *s) + { -S->top =-1; the return ;Bayi } the the //Reference:http://www.cnblogs.com/yuxi/archive/2007/02/10/647076.html - //and some books, starting with the double pointers I used, because I think to modify the pointer's contents, you should modify the pointer pointer in the child function, that is, the pointer address, but there will be an error.
"Small white growth"--sequential stack (c language version)