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

    ···

  • 相关阅读:
    第6天c#基础结构体和数组
    第5天c#基础for循环和enum
    第4天c#基础switch和while循环
    第3天c#按位运算和增减buff
    第2天c#基础
    第1天c#基础语法
    背景图层填充底色调密度
    如何在运行里添加命令
    网站
    BAT设置
  • 原文地址:https://www.cnblogs.com/yldf/p/11900173.html
Copyright © 2011-2022 走看看