zoukankan      html  css  js  c++  java
  • 顺序栈C语言实现

    “`

    #include <stdio.h>
    
    #define MAXSIZE 10001
    #define ELEMTYPE int
    #define STACK_EMPTY -9999
    #define N 10
    
    typedef struct stack
    {
        ELEMTYPE data[MAXSIZE];
        int top;
    } Seq_Stack;
    
    
    void initStack(Seq_Stack *S);
    void push(Seq_Stack *S,ELEMTYPE e);
    ELEMTYPE pop(Seq_Stack *S);
    int isStackEmpty(Seq_Stack *S);
    int isStackFull(Seq_Stack *S);
    void printStack(Seq_Stack *S);
    int main(void)
    {
        Seq_Stack Seq_S;
        initStack(&Seq_S);
        int i;
        for(i=1;i<=N;++i)
        {
            push(&Seq_S,i);
        }
        printStack(&Seq_S);
        return 0;
    }
    
    void initStack(Seq_Stack *S)
    {
        S->top = -1;
    }
    
    int isStackEmpty(Seq_Stack *S)
    {
    
        return S->top == -1;
    }
    int isStackFull(Seq_Stack *S)
    {
        if(S->top == MAXSIZE-1) return 1;
        return 0;
    
    }
    
    void push(Seq_Stack *S,ELEMTYPE e)
    {
        if(isStackFull(S)) return;
        S->data[++ S->top] = e;
    }
    ELEMTYPE pop(Seq_Stack *S)
    {
        if(isStackEmpty(S)) return STACK_EMPTY;
        return S->data[S->top --];
    }
    
    void printStack(Seq_Stack *S)
    {
        while(!isStackEmpty(S))
        {
            printf("%d	",pop(S));
        }
    }
    

    ···

  • 相关阅读:
    2018ddctf wp
    装饰器
    python作用域
    闭包
    迭代器
    ord() expected string of length 1, but int found
    pygm2安装问题
    elf逆向入门
    【POJ
    【POJ
  • 原文地址:https://www.cnblogs.com/yldf/p/6249905.html
Copyright © 2011-2022 走看看