zoukankan      html  css  js  c++  java
  • 【 数据结构(C语言)】栈的应用——行编辑程序

    行编辑程序

    /**
    **  2017.11.4
    **  Ahthor:799
    **  数制转换
    **
    ***/
    #include <bits/stdc++.h>
    using namespace std;
    #define STACK_INIT_SIZE 100 /// 存储空间初始分配
    #define STACK_INCREMENT 10 /// 存储空间分配增量
    #define ElemType char
    #define Status int
    #define OK 1
    #define ERROR -1
    #define OVERFLOW -2
    typedef struct
    {
        ElemType *base;
        ElemType *top;
        int stacksize;
    } SqStack;
    Status InitStack (SqStack &S)
    {
        S.base = (ElemType * )malloc(STACK_INIT_SIZE * sizeof(ElemType));
        if (!S.base) exit(OVERFLOW);
        S.top = S.base;
        S.stacksize = STACK_INIT_SIZE;
        return OK;
    }
    Status DestroyStack(SqStack &S)
    {
        for (ElemType *index = S.base; index != S.top; index ++)
        {
            free(index);
        }
        free(&S);
        return OK;
    }
    Status ClearStack(SqStack &S)
    {
        for (ElemType *index = S.base+1; index != S.top; index ++)
        {
            free(index);
        }
        S.top = S.base;
        return OK;
    }
    Status IsEmptyStack(SqStack &S)
    {
        if (S.base == S.top) return true;
        else return false;
    }
    Status LengthStack(SqStack &S)
    {
        return S.top - S.base;
    }
    ElemType  GetTop(SqStack &S)
    {
        if (S.top == S.base) return ERROR;
        ElemType e = *(S.top - 1);
        return e;
    }
    Status Push(SqStack &S,ElemType &e)
    {
        if (S.top - S.base >= S.stacksize)
        {
            S.base = (ElemType *) realloc (S.base,(S.stacksize + STACK_INCREMENT) * sizeof(ElemType));
            if (!S.base)exit(OVERFLOW);
            S.top = S.base + S.stacksize;
            S.stacksize += STACK_INCREMENT;
        }
        *S.top = e;
        S.top ++;
        return OK;
    }
    Status Pop(SqStack &S, ElemType &e)
    {
        if (S.top == S.base) return ERROR;
        e = * --S.top;
        return OK;
    }
    Status TrverseStack(SqStack &S)
    {
        for (ElemType *index = S.base; index != S.top; index ++)
        {
            cout<<*index<<" ";
        }
        cout<<endl;
        return OK;
    }
    void  LineEdit()
    {
    
    }
    int main()
    {
        SqStack * St = (SqStack *) malloc(sizeof(SqStack));
        InitStack (*St);
        char str[50],tmp;
        cin>>str;
        cout<<" str "<<str <<endl;
        for (int i=0; i<strlen(str) ; i++)
        {
           switch(str[i])
           {
               case'#':Pop(*St,tmp);break;
               case'@':ClearStack(*St);break;
               default:Push(*St,str[i]);break;
           }
    
        }
        TrverseStack(*St);
        return 0;
    }
    
    
    
    
  • 相关阅读:
    MIME 部分扩展名与类型对应
    sql server 表变量、表类型、临时表
    SqlBulkCopy使用注意事项
    SQL Server为啥使用了这么多内存?
    SQL SERVER下有序GUID和无序GUID作为主键&聚集索引的性能表现
    DQL、DML、DDL、DCL的概念与区别
    IIS解决CPU和内存占用率过高的问题
    SQL Server 表变量和临时表的区别
    I Count Two Three(打表+排序+二分查找)
    AC自动机入门经典题目(两种表达方式)
  • 原文地址:https://www.cnblogs.com/sxy-798013203/p/7783213.html
Copyright © 2011-2022 走看看