zoukankan      html  css  js  c++  java
  • SoftwareDataStructure 三年一直迷糊的链表

    2017-11-05 23:31:32 三年来其实一直迷糊的链表顿悟

    三年前 2014年下半年一直未理解而死敲代码,希望能量变引起质变的 数据结构中  链表的顿悟

    (查找算法中的二分查找。排序中的快速排序已与2015年专攻 JavaScript 时理解突破了)

    第一本 算法学习书《算法精解》以及让我理解了排序和查找 分治算法的书

     

    在学习 Java 描述的 数据结构时,对链表有了新的理解,FirstNode 的 插入及重置,默认构造函数的实现。

    插入的部分:

    newNode 不再存在,参数 newEntry 也是如此,行为像是一个局部变量。

    继续插入新的节点时,注意 Node 的两个构造函数

    1. 第一个构造函数 Node Pointer 为null, 为第一个节点所准备的。

    2. 常规的链中的节点:有data,有 pointer. 与 Node自动对应。

     1 public final class LinkedBag<T> implements BagInterface<T>{
     2 
     3     private Node firstNode;
     4     private int numberOfEntries;
     5 
     6     public LinkedBag() {
     7         firstNode = null;
     8         numberOfEntries = 0;
     9     } // end default constructor
    10 
    11     private class Node // private inner class
    12     {
    13         private T data; // Entry in bag
    14         private Node next; // Link to next node
    15 
    16         private Node(T dataPortion)
    17         {
    18             this(dataPortion, null);
    19         } // end constructor
    20 
    21         private Node(T dataPortion, Node nextNode)
    22         {
    23             data = dataPortion;
    24             next = nextNode;
    25         } // end constructor
    26 
    27         private T getData(){
    28             return data;
    29         }
    30 
    31         private void setData(T newData){
    32             data = newData;
    33         }
    34 
    35         private Node getNextNode(){
    36             return next;
    37         }
    38 
    39         private void setNextNode(Node nextNode){
    40             next = nextNode;
    41         }
    42     }
    43 
    44     /** Adds a new entry to this bag.
    45      * @param newEntry  The object to be added as a new entry.
    46      *                  @return True
    47      */
    48     public boolean add(T newEntry) // OutOfMemoryError possible
    49     {
    50         // Add to beginning of chain.
    51         Node newNode = new Node(newEntry);
    52         //newNode.next = firstNode; // Make new node reference rest of chain.
    53                                     //(first node is null if chain is empty)
    54         newNode.setNextNode(firstNode);
    55 
    56         firstNode = newNode;
    57         numberOfEntries++;
    58 
    59         return true;
    60     }
    View Code
  • 相关阅读:
    使用Oracle PROFILE控制会话空闲时间
    ORACLE sid,pid,spid总结
    总结:基于Oracle Logminer数据同步
    从操作系统rm数据文件后,利用句柄与rman恢复的过程。(已验证)
    SPOJ GCDEX (数论)
    C++类构造函数
    [置顶] 删除:大数据取舍之道读书笔记
    paip.c++ qt 图片处理 检测损坏的图片
    paip.c++ qt 目录遍历以及文件操作
    AJAX最简单的原理以及应用
  • 原文地址:https://www.cnblogs.com/masterSoul/p/7790013.html
Copyright © 2011-2022 走看看