zoukankan      html  css  js  c++  java
  • 十 、链表的java实现

    原理图:

    源代码:

    NODE:

    public class Node {
    int data; //数据域
    public Node next; //指针域

    public Node(int value) {
    // TODO Auto-generated constructor stub
    this.data = value;
    }
    public void display() //显示结点的值
    {
    System.out.print(data + " ");
    }
    }

    LinkList:

    public class Linklist {
    private Node first; //头结点

    public Linklist() { //构造方法
    // TODO Auto-generated constructor stub
    first =null;
    }
    public void insert(int value) //头结点之前插入结点
    {
    Node node = new Node(value);
    node.next = first;
    first= node;
    }

    public void delete() //头结点后删除结点
    {
    Node tmp = first.next;
    first.next = tmp.next;
    }

    public void display() //显示全部的结点
    {
    Node current = first;
    while(current!= null)
    {
    current.display();
    current = current.next;
    }
    System.out.println();
    }

    public void find(int value) //根据数值查找结点
    {
    Node current = first;
    while(current.data != value)
    {
    current = current.next;
    }
    current.display();

    }
    public void findDele(int value) //查找数据并删除结点
    {
    Node current = first;
    Node pro =current ;
    if(first.data == value) //第一个就是的话
    {
    first = first.next;

    }
    else
    {
    while(current.data != value)
    {
    pro = current;
    current = current.next;
    }
    pro.next = current.next;
    }

    }
    }

  • 相关阅读:
    Configure文件学习
    实用文章:常用开源协议详细解析
    openwrt的sysupgrade和factory固件的区别
    Linux块设备和字符设备
    eclipse代码补全按键修改成Tab
    Hadoop环境搭载
    比特币中难度调整
    共识机制
    比特币交易本质--UTXO(Unspent Transaction Output)
    多重签名
  • 原文地址:https://www.cnblogs.com/fyz666/p/8461499.html
Copyright © 2011-2022 走看看