zoukankan      html  css  js  c++  java
  • 数据结构-单向链表

    Node类

    //链表结构
    public class Node {
        //数据
        public long data;
        //指针,连接下个结点
        public Node next;
    
        public Node(long value){
            this.data=value;
        }
    
        public void display(){
            System.out.print(data+" ");
        }
    }
    
    

    链表的常用方法

    public class LinkList {
        //头结点
        private Node first;
    
        //构造方法
        public LinkList(){
            first=null;
        }
    
        //每次添加都添加在开头
        public void insertFirst(long value){
            Node node = new Node(value);
            node.next=first;
            first=node;
    
    
        }
    
        //删除头结点
        public Node deleteFirst(){
            Node temp = first;
            first=temp.next;
            return temp;
    
        }
    
        //遍历
        public void display(){
            Node cur = first;
            while (cur!=null){
                cur.display();
                cur=cur.next;
            }
            System.out.println();
        }
    
        //根据值查找结点
        public Node find(long value){
            Node cur = first;
            while (cur.data!=value){
                if (cur.next==null){
                    return null;
                }
                cur=cur.next;
            }
            return cur;
        }
    
        //删除指定值
        public Node delete(long value){
            Node cur = first;
            Node pre = first;
            while (cur.data!=value){
                if (cur.next==null){
                    return null;
                }
                pre = cur;
                cur = cur.next;
    
            }
            if (cur==first){
                first=first.next;
            }
            pre.next = cur.next;
            return cur;
        }
    }
    
    
  • 相关阅读:
    MOSS中实现自动上传图片
    2008年最后一天了
    MOSS中使用无刷新的日历日程控件破解版
    UC R2 Metro Tranning
    明智IT, 逆势成长概述
    RMS Client如何使用AD组策略部署
    MOSS & Project Server 2007
    MOSS & SSO 系列2
    Dynamics AX 2009 Trainning
    MOSS & SSO 系列4
  • 原文地址:https://www.cnblogs.com/hellosiyu/p/12465988.html
Copyright © 2011-2022 走看看