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;
    }

    }
    }

  • 相关阅读:
    ASP.net 网站项目:Fckeditor使用StepByStep
    SQL2005触发器写法
    Android 中 PopupWindow使用
    storyboard学习笔记-1
    判断两矩形是否相交
    CListCtrl 使用
    字符串和数字之间的转换(Unicode)
    【转】全特化/偏特化
    判断点是否在多边形内——射线法
    c++强制转化
  • 原文地址:https://www.cnblogs.com/fyz666/p/8461499.html
Copyright © 2011-2022 走看看