zoukankan      html  css  js  c++  java
  • 顺序栈的操作

    #include<stdio.h>
    #include<malloc.h>
    #include<stdlib.h>
    #define MAXSIZE 100
    typedef int SElemType;
    typedef struct SqStack {
    	SElemType* base;//栈底指针
    	SElemType* top;//栈顶指针
    	int stacksize;//栈可用最大容量
    }SqStack;
    
    /*
    	栈的初始化
    */
    void InitStack(SqStack& S) {
    	S.base = (SElemType*)malloc(sizeof(SElemType) * MAXSIZE);
    	if (!S.base)exit(-1);
    	S.top = S.base;
    	S.stacksize = MAXSIZE;
    }
    
    /*
    	判断顺序栈是否为空
    */
    bool StackEmpty(SqStack S) {
    	if (S.base == S.top)
    	{
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    /*
    	求顺序栈长度
    */
    int StackLength(SqStack S) {
    	return S.top - S.base;
    }
    
    /*
    	清空顺序栈
    */
    int ClearSqStack(SqStack& S) {
    	if (S.base)
    	{
    		S.top = S.base;
    	}	
    	return 1;
    }
    
    /*
    	销毁顺序栈
    */
    int DestroyStack(SqStack& S) {
    	if (S.base)
    	{
    		free(S.base);
    		S.stacksize = 0;
    		S.base = S.top = NULL;
    	}
    	return 1;
    }
    
    /*
    	顺序栈的入栈
    */
    int Push(SqStack& S, SElemType e) {
    	if (S.top - S.base == S.stacksize)return -1;//栈满
    	*S.top = e;
    	S.top++;
    	return 1;
    }
    
    /*
    	顺序栈的出栈
    */
    int Pop(SqStack& S, SElemType& e) {
    	if (S.base == S.top) return -1;
    	e = *S.top;
    	S.top--;
    	return 1;
    }
    
    
    int main() {
    
    	return 0;
    }
    
    我亦无他,惟手熟尔
  • 相关阅读:
    2.由浅入深解析 SimpleDateFormat
    7.如何在Maven项目中引入自己的jar包
    6.Java英文缩写详解
    6.JXL操作Excel
    5.Apache POI使用详解
    4.Properties文件的加载和使用
    3.java.util.logging.Logger使用详解
    2.使用dom4j解析XML文件
    jdk、jre、spring、java ee、java se
    JVM架构
  • 原文地址:https://www.cnblogs.com/AsuraPlus/p/15518359.html
Copyright © 2011-2022 走看看