zoukankan      html  css  js  c++  java
  • exp3.1实现顺序栈的各种操作

    #include<iostream>
    using namespace std;
    #include<malloc.h>
    typedef char Elem;
    typedef struct{
    Elem a[50];
    int top;
    }A;
    void Create(A *&T)
    {
    T=(A *)malloc(sizeof(A));
    T->top=-1;
    }
    void empty1(A *T)
    {
    if(T->top==-1)
    cout<<"This stack is empty!"<<endl;
    else
    cout<<"This stack is not empty!"<<endl;
    }
    void Insert(A *&T,int i,Elem e)
    {
    T->a[i]=e;
    T->top++;
    }
    void Display(A *T)
    {
    cout<<"The deleted stack element is:";
    for(int i=T->top;i>=0;i--)
    {
    cout<<T->a[i];
    }
    }
    int main()
    {
    A *s1;
    int i;
    Elem e;
    Create(s1);
    empty1(s1);
    for(i=0;i<5;i++)
    {
    cin>>e;
    Insert(s1,i,e);
    }
    empty1(s1);
    Display(s1);
    return 0;
    }

  • 相关阅读:
    随笔1
    随笔
    shared_ptr<> reset
    c++模板库(简介)
    rockmongo用法
    随笔
    TEXT宏,TCHAR类型
    sprintf
    基于SOA的银行系统架构
    大纲6 信息化规划与管理
  • 原文地址:https://www.cnblogs.com/xww115/p/7683655.html
Copyright © 2011-2022 走看看