"Small white growth"--sequential stack (c language version)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.