LinkedList如何在java项目中运用
                                            本篇文章为大家展示了LinkedList如何在java项目中运用 ,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

成都创新互联公司自2013年起,先为常德等服务建站,常德等地企业,进行企业商务咨询服务。为常德企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
java LinkedList的实例详解
实例代码:
public class LinkedListimplements List , Deque { Node first; Node last; int size; public boolean add(E e) { final Node l = last; final Node newNode = new Node<>(l, e, null); last = newNode; if (l == null) first = newNode; else l.next = newNode; size++; modCount++; return true; } private static class Node { E item; Node next; Node prev; Node(Node prev, E element, Node next) { this.item = element; this.next = next; this.prev = prev; } } } 
单链表反转:
/**  
   * 递归,在反转当前节点之前先反转后续节点  
   */  
  public static Node reverse(Node head) {  
    if (null == head || null == head.getNextNode()) {  
      return head;  
    }  
    Node reversedHead = reverse(head.getNextNode());  
    head.getNextNode().setNextNode(head);  
    head.setNextNode(null);  
    return reversedHead;  
  }  
  
  /**  
   * 遍历,将当前节点的下一个节点缓存后更改当前节点指针  
   *  
   */  
  public static Node reverse2(Node head) {  
    if (null == head) {  
      return head;  
    }  
    Node pre = head;  
    Node cur = head.getNextNode();  
    Node next;  
    while (null != cur) {  
      next = cur.getNextNode();  
      cur.setNextNode(pre);  
      pre = cur;  
      cur = next;  
    }  
    //将原链表的头节点的下一个节点置为null,再将反转后的头节点赋给head    
    head.setNextNode(null);  
    head = pre;  
      
    return head;  
  } 
对于数组问题,一般我们要新建数组,必要时移动下标
上述内容就是LinkedList如何在java项目中运用 ,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
网页名称:LinkedList如何在java项目中运用
网址分享:http://www.cqwzjz.cn/article/pohhge.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 