zoukankan      html  css  js  c++  java
  • 单向链表的建立(尾部插入法)

    class ListNode {
        ListNode next;
        int val;
        public ListNode(int x) {
            val = x;
        }
    }
    public class LinkList {
        private ListNode curr = new ListNode(-1);
        private ListNode head = curr;
        public void appendToTail(int d) {
            ListNode tail = new ListNode(d);
            curr.next = tail;
            curr = curr.next;
        }
        public void printAppendToTail() {
            while (head.next != null) {
                System.out.println(head.next.val);
                head = head.next;
            }
        }
        
        public static void main(String[] args) {
            LinkList llist = new LinkList();
            for (int i = 1; i < 10; i++) {
                llist.appendToTail(i);
            }
            llist.printAppendToTail();
        }
    }
  • 相关阅读:
    gRPC初识
    Go操作MySQL
    Go语言操作Redis
    Markdown 教程
    Go操作MongoDB
    Go操作NSQ
    Go操作kafka
    Go操作etcd
    Go语言获取系统性能数据gopsutil库
    influxDB
  • 原文地址:https://www.cnblogs.com/lasclocker/p/4856233.html
Copyright © 2011-2022 走看看