zoukankan      html  css  js  c++  java
  • Java

      熟悉一下Java。。。

    package ChianTable;
    
    import java.util.Scanner;
    
    /**
     * Created by Administrator on 2018/3/26.
     */
    public class LinkedList {
    
        private LinkedList prev;
        private LinkedList next;
        private int val;
    
        private LinkedList head;
        private LinkedList rear;
    
        public LinkedList() {
            super();
        }
    
        public LinkedList(LinkedList p, LinkedList n, int v) {
            super();
            this.prev = p;
            this.next = n;
            this.val = v;
        }
    
        public LinkedList Create() {
    
            Scanner type = new Scanner(System.in);
            int val = type.nextInt();
    
            LinkedList nextNode = new LinkedList(null, null, val);
            this.head = nextNode;
            while ((val = type.nextInt()) != 0) {
                LinkedList curr = new LinkedList(nextNode, null, val);
                nextNode.next = curr;
                nextNode = curr;
            }
            this.rear = nextNode;
            nextNode.next = null;
    
            return this.head;
        }
    
        public void nextprint() {
            if (this.head != null) {
                System.out.println(this.head.val);
                this.head = this.head.next;
                nextprint();
            }
        }
    
        public void prevprint() {
            if (this.rear != null) {
                System.out.println(this.rear.val);
                this.rear = this.rear.prev;
                prevprint();
            }
        }
    
    }

      测试:

    package main;
    
    
    import ChianTable.LinkedList;
    
    public class Main {
    
        public static void main(String [] args) {
    
            LinkedList linkedlist = new LinkedList();
    
            linkedlist.Create();
            linkedlist.nextprint();
            linkedlist.prevprint();
    
        }
    }
    

      

  • 相关阅读:
    看雪-课程-加密与解密基础
    Windows API-Wininet&WinHTTP
    OS-Windows-bat-不等待当前命令返回继续执行后续指令
    Code-OPC DA- OPC Client Code Demo
    OS-Windows-Close Windows Error Reporting
    C-长度修饰符
    Code-Linux-time_t
    Windows-bat-Path
    Code-C++-CTime&ColeDateTime
    c++命名规范、代码规范和参数设置
  • 原文地址:https://www.cnblogs.com/darkchii/p/8653921.html
Copyright © 2011-2022 走看看