zoukankan      html  css  js  c++  java
  • Java链栈

    package com.lxm.customDataStructure;
    
    public class LinkStack<T>{
        class Node<T>{
            T data;
            Node next;
            Node(T data)
            {   
                this.data=data;
                this.next = null;
            }
        }
    
        Node<T> head;
    
        public LinkStack(T data)
        {
            this.head = null;
        }
    
        public boolean isEmpty()
        {
            return this.head==null;
        }
    
        public void push(T e)
        {
            Node temp = new Node(e);
            temp.next = this.head;
            this.head = temp;
        }
    
        public T pop()
        {
            if(this.isEmpty()) return null;
            Node temp = this.head;
            this.head  = temp.next;
            return (T) temp.data;
        }
    
        public static void main(String[] args)
        {
            LinkStack<Integer> S = new LinkStack<Integer>(0);
            for(int i=0;i<10;i++)
            {
                S.push(i+1);
            }
    
            while(S.isEmpty()==false)
            {
                System.out.print(S.pop()+"	");
            }
            System.out.println();
        }
    }
  • 相关阅读:
    1、如何使用Azure Rest API创建虚拟机
    Ansible---2的Roles使用
    linux下的shell脚本
    生成器 yield和协程
    xshell
    markdown的使用
    加密
    Hbuilder打包app
    尾递归
    jupyter
  • 原文地址:https://www.cnblogs.com/yldf/p/11900143.html
Copyright © 2011-2022 走看看