zoukankan      html  css  js  c++  java
  • 第五次课程作业

    第五次课程作业

    GIT链接

    四则运算代码框架:

    具体实现在上方git链接。

    对栈的学习:

    下面为自己写的栈的代码

    #include<iostream>
    using namespace std;
    class Stack{
    private:
    	int top;
    	int *a;
    	int size;
    public:
    	void push(int);//进栈
    	void pop();//出栈
    	bool stackempty();//是否为空
    	bool stackfull();//是否满
    	Stack();
    	Stack(int);//构造栈,大小自拟
    };
    Stack::Stack(int how_many){
    	size=how_many;
    	a=(int *)malloc(4*how_many);
    	top=0;
    }
    void Stack::push(int t){
    	if(!stackfull()){
    		*(a+top)=t;
    		top++;
    	}else cout<<"Error:the stack is full"<<endl;
    }
    void Stack::pop(){
    	if(!stackempty()){
    		top--;
    	}else cout<<"Error:the stack is empty"<<endl;
    }
    bool Stack::stackempty(){
    	if(top==0)return true;
    	return false;
    }
    bool Stack::stackfull(){
    	if(top==size)return true;
    	return false;
    }
    

    栈可以用数组写也可以用链表写,数组比较方便点。

    感想:

    栈的用途极为广泛,在源程序编译中表达式的计算、过程的嵌套调用和递归调用等都要用到栈。

  • 相关阅读:
    拦截器
    Ajax
    JSON
    数据处理及跳转
    RestFul和控制器
    第一个MVC程序
    什么是SpringMVC
    回顾MVC
    声明式事务
    微软最强 Python 自动化工具开源了!不用写一行代码!
  • 原文地址:https://www.cnblogs.com/qwe1/p/6890855.html
Copyright © 2011-2022 走看看