tsaiwn@magpie % gcc stkmain.c stk.c
tsaiwn@magpie % ./a.out
53 770 880 

tsaiwn@magpie % cat -n stk.c
     1 // stk.c -- CopyLeft by tsaiwn@csie.nctu.edu.tw
     2 // |(Stack) P C(Queue; ƶ)OƵcܭn]²檺
     3 // uʸƵc!
     4 // HUҤlDnbpbº C y@X@Ӱ| (Stack),
     5 //ܩ|wqHΥγ~аѦҭpҥάOƵcҥ,
     6 //Ϊ̥ google.com @Ӥ]iݨ\hһP :-)
     7 // `NHܼƭn static ?  
     8 // ==> only can see by functions in this File  ==> Information hiding!
     9 //#define NELEMENT 99     // OK
    10    enum{NELEMENT=99};     // better
    11    static int data[NELEMENT];    // why static ?
    12    static int stkptr = -1;      // stack is empty
    13 // HUTӨƫŧiiiL
    14       void push(int);
    15       void pop(void);
    16       int top(void);
    17 //////
    18 void push(int x) {
    19     stkptr++;
    20     data[stkptr] = x;
    21 }  
    22 int top(void) {
    23     return data[stkptr];
    24 }
    25 void pop(void) {
    26     if(stkptr> -1) --stkptr;
    27 }
    28 int empty(void){ return (stkptr <= -1) ;}
    29 int isfull(void){ return (stkptr >= NELEMENT-1);}
tsaiwn@magpie % cat -n stkmain.c
     1 // stkmain.c --- ϥ stk.c | (Stack)
     2 // gcc stkmain.c stk.c   ;  ./a.out
     3 ///
     4 // DPҼ{: pGݭn stack n?
     5 // : ²kOstk.cƻst@file, קfunction nameҦppush2/pop2
     6 // ]UfileܼƦ static O@, |Q䥦 file  functions ݨ!
     7 #include<stdio.h>
     8 int main( ){
     9    push(880);
    10    push(770);
    11    push(53);
    12    while(!empty()){
    13       printf("%d ", top( ) );
    14       pop();
    15    }
    16    printf("\n");
    17 }
tsaiwn@magpie % gcc stkmain.c stk.c
tsaiwn@magpie % ./a.out
53 770 880 

tsaiwn@magpie % exit
exit
