zoukankan      html  css  js  c++  java
  • 只写了一部分功能:

    View Code
    #include<stdio.h>
    #include<stdlib.h>
    #include<malloc.h>
    #define STACK_INIT_SIZE 100
    #define STACKINCREMENT 10
    typedef struct
    {
        int *base;
        int *top;
        int stacksize;
    }SqStack;
    void InitStack(SqStack &S);
    int DestroyStack(SqStack &S);
    int ClearStack(SqStack &S);
    int StackEmpty(SqStack &S);
    int StackLength(SqStack &S);
    int GetTop(SqStack &S);
    void Push(SqStack &S,int e);
    int Pop(SqStack &S);
    void StackTraverse(SqStack &S);
    void main()
    {
        SqStack S;
        InitStack(S);
        Push(S,3);
        Push(S,5);
        StackTraverse(S);
        int m=Pop(S);
        StackTraverse(S);
    }
    void InitStack(SqStack &S)
    {
        //puts("Init Stack");
        S.base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
        if(!S.base)
            exit(-1);
        S.top=S.base;
        S.stacksize=STACK_INIT_SIZE;
    }
    void Push(SqStack &S,int e)
    {
        //Push e into Stack;
        if(S.top-S.base>=S.stacksize)
        {
            S.base=(int *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
        if(!S.base)
            exit(-1);
        S.top=S.base+S.stacksize;
        S.stacksize+=STACKINCREMENT;
        }
        *S.top++=e;//S.top++;*S.top=e;
    }
    
    int Pop(SqStack &S)
    {
        //Pop the top Element
        if(S.top==S.base)
            exit(-1);
        int e=*(--S.top);
        return e;
    }
    void StackTraverse(SqStack &S)
    {
        //Print all the Elem
        if(S.top==S.base)
            exit(0);
        puts("Stack Elem :");
        int *e=S.top;
        while(e>S.base)
        {
            printf("%d\n",*(--e));
        }
    }
  • 相关阅读:
    Permutations II
    Add Binary
    Integer to Roman
    Roman to Integer
    Word Break
    完整记录一则Oracle 11.2.0.4单实例打PSU补丁的过程
    SQL Tuning 基础概述06
    SQL Tuning 基础概述05
    SQL Tuning 基础概述04
    SQL Tuning 基础概述03
  • 原文地址:https://www.cnblogs.com/wuyihong/p/2693710.html
Copyright © 2011-2022 走看看