zoukankan      html  css  js  c++  java
  • stack 栈的实现

      今天晚上去「南哪」听了场AI的讲座,除了话筒真心不给力之外,算是对微软这方面的进展有了更多了解,毕竟是半宣传性质的活动吧。

      光听这些是没用的,眼下还是打好基础,多尝试学点新技术,拓宽能力和视野比较重要。

      比较匆忙,这次算是重新过了一遍过去写的代码,把命名和格式改进了一下。

       

    Stack 栈的C++实现

    main函数是把数字翻转输出

    #include <iostream>
    using namespace std;
    
    typedef int dataType;
    
    struct StackNode
    {
    	dataType data;
    	StackNode * next;
    };
    
    class stack
    {
    	StackNode *top =NULL;
    	int NodeNumber=0;
    	public:
    		int get_node_number()
    		{
    			return NodeNumber;
    		}
    		
    		void push(dataType data)
    		{
    			StackNode *p=new StackNode;
    			p->data=data;
    			p->next=top;
    			top=p;
    			++NodeNumber;
    		}
    		
    		dataType pop()
    		{
    			dataType popNum=this->top->data;
    			top = top->next;
    			--NodeNumber;
    			return popNum;
    		}
    	
    		bool is_stack_full()
    		{
    			if (this->top == NULL)
    				return true;
    			else
    				return false;
    		}
    };
    
    int main() {
    	stack * n_stack=new stack;
    	int n;
    	cout<<"Input the number on the next line!"<<endl;
    	cin>>n;
    	while(n!=0)
    	{
    		n_stack->push(n%10);
    		n=n/10;
    	}
    	while(!n_stack->is_stack_full())
    		cout<<n_stack->pop();
    	
    	return 0;
    	
    }
    

      晚安世界!

  • 相关阅读:
    Visual Studio中配置Beyond Compare为版本比较工具
    Restsharp常见格式的发送分析
    dex2jar反编译dex文件
    Apktool反编译apk资源文件
    远程桌面复制粘贴突然失效的问题
    C#4.0 HTTP协议无法使用TLS1.2的问题
    TFS-Git官方教程
    git 换行符问题
    NPM升级
    NodeJS笔记(一)-免安装设置
  • 原文地址:https://www.cnblogs.com/learn-to-rock/p/5331171.html
Copyright © 2011-2022 走看看