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));
        }
    }
    

    ···

  • 相关阅读:
    spring_three
    报错:java.sql.SQLException: The server
    Spring_two
    Spring_One
    Mybatis中的collection和association一关系
    Mybatis_three
    文件操作1
    面向对象编程三大特征7
    面向对象编程三大特征6
    面向对象编程三大特征5
  • 原文地址:https://www.cnblogs.com/yldf/p/6249905.html
Copyright © 2011-2022 走看看