[{"data":1,"prerenderedAt":4341},["ShallowReactive",2],{"\u002Fblog\u002FLinked-Lists-&-Doubly-Linked-Lists":3,"post-count":3927,"series-global-data":3928,"authors-all":4044,"series-sidebar-none":4239,"sidebar-authors":4240},{"id":4,"title":5,"author":6,"body":7,"date":3915,"description":3916,"draft":3917,"edited_at":3915,"extension":3918,"featured_image":3919,"meta":3920,"navigation":3921,"path":3922,"pinned":3917,"seo":3923,"sitemap":3924,"stem":3925,"tags":3919,"__hash__":3926},"blog\u002Fblog\u002FLinked-Lists-&-Doubly-Linked-Lists.md","Linked Lists & Doubly Linked Lists","chinono",{"type":8,"value":9,"toc":3849},"minimark",[10,33,38,44,59,69,76,98,131,135,141,163,174,194,199,202,207,230,235,250,253,257,260,271,277,283,290,294,297,311,413,416,422,425,443,454,463,467,480,484,529,533,567,570,576,585,589,618,627,633,637,664,669,678,682,694,755,758,766,777,846,849,856,958,971,978,1081,1088,1091,1298,1313,1320,1428,1435,1448,1660,1667,1674,1866,1869,1873,1890,1893,1897,1914,1920,1923,1927,1938,1944,1948,1958,1964,1968,1980,1983,1989,1996,2000,2003,2027,2031,2034,2046,2050,2054,2210,2214,2326,2330,2333,2358,2365,2374,2492,2499,2502,2614,2621,2846,2870,2873,2897,2901,2905,2997,3001,3080,3089,3093,3096,3102,3218,3224,3231,3340,3343,3349,3607,3613,3642,3645,3653,3780,3783,3787,3790,3838,3845],[11,12,13,14,18,19,23,24,27,28,32],"p",{},"If you've ever used ",[15,16,17],"code",{},"ArrayList"," in Java and wondered what the ",[20,21,22],"em",{},"other"," list — ",[15,25,26],{},"LinkedList"," — is doing differently, this post is for you. We're going to walk through what linked lists are, why they exist alongside arrays, and how to build one from scratch. Then we'll level up to ",[29,30,31],"strong",{},"doubly linked lists",", which are a small twist on the idea with surprisingly nice properties.",[34,35,37],"h2",{"id":36},"_1-where-linked-lists-live-the-java-collection-framework","1. Where Linked Lists Live: The Java Collection Framework",[11,39,40,41,43],{},"Before diving in, it helps to know where ",[15,42,26],{}," sits in Java's standard library.",[11,45,46,47,50,51,54,55,58],{},"A ",[29,48,49],{},"collection"," is just a container object that holds a group of other objects (called ",[20,52,53],{},"elements","). Java's ",[15,56,57],{},"java.util"," package has an entire hierarchy of these:",[60,61,66],"pre",{"className":62,"code":64,"language":65},[63],"language-text","Iterable (interface)\n   └── Collection (interface)\n         ├── List (interface)\n         │     ├── ArrayList\n         │     ├── LinkedList   ← our star today\n         │     └── Vector → Stack\n         ├── Queue (interface)\n         │     ├── PriorityQueue\n         │     └── Deque → ArrayDeque\n         └── Set (interface)\n               ├── HashSet\n               ├── LinkedHashSet\n               └── SortedSet → TreeSet\n","text",[15,67,64],{"__ignoreMap":68},"",[11,70,71],{},[72,73],"img",{"alt":74,"src":75},"0.54","https:\u002F\u002Fraw.githubusercontent.com\u002FChinHongTan\u002Fblog\u002Fmain\u002Fpublic\u002Fimages\u002Fuploads\u002F1778666021685-Screenshot_2026-05-13_at_5.53.18_PM.png",[11,77,78,79,82,83,86,87,90,91,93,94,97],{},"The orange boxes in the picture are ",[29,80,81],{},"interfaces"," (contracts that say ",[20,84,85],{},"what"," operations exist), and the blue ones are ",[29,88,89],{},"classes"," (actual implementations). ",[15,92,26],{}," is one concrete way to implement the ",[15,95,96],{},"List"," interface.",[11,99,100,101,104,105,108,109,108,112,108,115,108,118,108,121,124,125,127,128,130],{},"The ",[15,102,103],{},"Collection"," interface defines operations every collection should support — things like ",[15,106,107],{},"add",", ",[15,110,111],{},"remove",[15,113,114],{},"contains",[15,116,117],{},"size",[15,119,120],{},"isEmpty",[15,122,123],{},"iterator",", and so on. Whether you use ",[15,126,17],{}," or ",[15,129,26],{},", you get all these methods.",[34,132,134],{"id":133},"_2-what-is-a-list-conceptually","2. What Is a List, Conceptually?",[11,136,46,137,140],{},[29,138,139],{},"list"," is an Abstract Data Type (ADT) that stores data in sequential order. Think of any everyday list — a class roster, a to-do list, books on a shelf. The common operations we care about are:",[142,143,144,148,151,154,157,160],"ul",{},[145,146,147],"li",{},"Retrieve an element",[145,149,150],{},"Insert a new element",[145,152,153],{},"Delete an element",[145,155,156],{},"Find how many elements are in the list",[145,158,159],{},"Check if an element exists",[145,161,162],{},"Check if the list is empty",[11,164,165,166,169,170,173],{},"The key word above is ",[29,167,168],{},"abstract",". A \"list\" doesn't say ",[20,171,172],{},"how"," the data is stored — only what you can do with it. There are two main ways Java actually implements lists under the hood:",[175,176,177,186],"ol",{},[145,178,179,182,183,185],{},[29,180,181],{},"Using an array"," — ",[15,184,17],{},". The array grows dynamically: when it gets full, Java creates a bigger one and copies everything over.",[145,187,188,182,191,193],{},[29,189,190],{},"Using a linked structure",[15,192,26],{},". Each element lives in its own little container (a \"node\"), and the nodes are chained together with references.",[195,196,198],"h3",{"id":197},"array-or-linked-list-which-should-you-use","Array or Linked List? Which Should You Use?",[11,200,201],{},"Both work. They have different trade-offs:",[11,203,204],{},[29,205,206],{},"Use an array (ArrayList) when:",[142,208,209,216,223],{},[145,210,211,212,215],{},"You need fast access by index (",[15,213,214],{},"get(5)"," is instant — O(1))",[145,217,218,219,222],{},"You mostly add to the ",[20,220,221],{},"end"," of the list",[145,224,225,226,229],{},"❌ Inserting or deleting in the ",[20,227,228],{},"middle"," is slow, because everything after it has to shift",[11,231,232],{},[29,233,234],{},"Use a linked list when:",[142,236,237,244,247],{},[145,238,239,240,243],{},"You frequently add or remove elements ",[20,241,242],{},"anywhere"," in the list",[145,245,246],{},"You don't need random access by index very often",[145,248,249],{},"❌ Getting the 500th element requires walking through 500 nodes",[11,251,252],{},"A good rule of thumb: arrays are like books on a shelf (easy to grab the 5th one, painful to insert a new book at position 2). Linked lists are like a chain of paper clips (easy to splice in or pull out anywhere, but you have to start from one end to find the middle one).",[34,254,256],{"id":255},"_3-introducing-the-linked-list-the-pop-chain-analogy","3. Introducing the Linked List: The Pop-Chain Analogy",[11,258,259],{},"Imagine a child's toy \"pop chain\" — each piece has a connector on one side and a socket on the other. To build a chain, you push the connector of one piece into the socket of the next.",[11,261,262,263,266,267,270],{},"A linked list works exactly like this. Each ",[29,264,265],{},"node"," is one piece, and each piece is ",[20,268,269],{},"linked"," to the next.",[11,272,273,276],{},[29,274,275],{},"Inserting"," a piece anywhere in the chain: you just break one connection, pop in the new piece, and reconnect. The other pieces don't move.",[11,278,279,282],{},[29,280,281],{},"Removing"," a piece: break the two connections around it, take it out, then bridge the two neighbors back together.",[11,284,285,286,289],{},"This is the magic of linked lists: ",[29,287,288],{},"insertion and deletion are local operations",". You only need to update the links right around the change — the rest of the list is undisturbed. With an array, inserting at the start means shifting every other element over by one. With a linked list, no shifting required.",[34,291,293],{"id":292},"_4-nodes-the-building-blocks","4. Nodes: The Building Blocks",[11,295,296],{},"Each node in a linked list has two parts:",[175,298,299,305],{},[145,300,100,301,304],{},[29,302,303],{},"element"," (the actual data — a String, an Integer, whatever)",[145,306,46,307,310],{},[29,308,309],{},"reference"," (or \"pointer\") to the next node\nIn Java, a node looks like this:",[60,312,316],{"className":313,"code":314,"language":315,"meta":68,"style":68},"language-java shiki shiki-themes github-light github-dark","class Node\u003CE> {\n    E element;        \u002F\u002F the data\n    Node\u003CE> next;     \u002F\u002F reference to the next node\n \n    public Node(E o) {\n        element = o;\n    }\n}\n","java",[15,317,318,341,351,365,371,389,401,407],{"__ignoreMap":68},[319,320,323,327,331,335,338],"span",{"class":321,"line":322},"line",1,[319,324,326],{"class":325},"szBVR","class",[319,328,330],{"class":329},"sScJk"," Node",[319,332,334],{"class":333},"sVt8B","\u003C",[319,336,337],{"class":325},"E",[319,339,340],{"class":333},"> {\n",[319,342,344,347],{"class":321,"line":343},2,[319,345,346],{"class":333},"    E element;        ",[319,348,350],{"class":349},"sJ8bj","\u002F\u002F the data\n",[319,352,354,357,359,362],{"class":321,"line":353},3,[319,355,356],{"class":333},"    Node\u003C",[319,358,337],{"class":325},[319,360,361],{"class":333},"> next;     ",[319,363,364],{"class":349},"\u002F\u002F reference to the next node\n",[319,366,368],{"class":321,"line":367},4,[319,369,370],{"class":333}," \n",[319,372,374,377,379,382,386],{"class":321,"line":373},5,[319,375,376],{"class":325},"    public",[319,378,330],{"class":329},[319,380,381],{"class":333},"(E ",[319,383,385],{"class":384},"s4XuR","o",[319,387,388],{"class":333},") {\n",[319,390,392,395,398],{"class":321,"line":391},6,[319,393,394],{"class":333},"        element ",[319,396,397],{"class":325},"=",[319,399,400],{"class":333}," o;\n",[319,402,404],{"class":321,"line":403},7,[319,405,406],{"class":333},"    }\n",[319,408,410],{"class":321,"line":409},8,[319,411,412],{"class":333},"}\n",[11,414,415],{},"A whole list, then, is a chain of these:",[60,417,420],{"className":418,"code":419,"language":65},[63],"head → [Chicago | next] → [Denver | next] → [Dallas | null] ← tail\n",[15,421,419],{"__ignoreMap":68},[11,423,424],{},"We keep two convenience references:",[142,426,427,435],{},[145,428,429,434],{},[29,430,431],{},[15,432,433],{},"head"," — points to the first node",[145,436,437,442],{},[29,438,439],{},[15,440,441],{},"tail"," — points to the last node",[11,444,445,446,449,450,453],{},"The very last node's ",[15,447,448],{},"next"," is ",[15,451,452],{},"null"," — that's how we know we've reached the end.",[455,456,457],"blockquote",{},[11,458,459,460,462],{},"Heads up: each node can physically live anywhere in memory. The ",[15,461,448],{}," pointers are what tie them together logically. This is different from an array, where elements are packed side-by-side in memory.",[34,464,466],{"id":465},"_5-building-a-list-step-by-step","5. Building a List Step by Step",[11,468,469,470,108,473,108,476,479],{},"Let's create a list of three city names: ",[15,471,472],{},"\"Chicago\"",[15,474,475],{},"\"Denver\"",[15,477,478],{},"\"Dallas\"",".",[195,481,483],{"id":482},"step-1-start-empty","Step 1: Start empty",[60,485,487],{"className":313,"code":486,"language":315,"meta":68,"style":68},"Node\u003CString> head = null;\nNode\u003CString> tail = null;\n\u002F\u002F The list is empty.\n",[15,488,489,509,524],{"__ignoreMap":68},[319,490,491,494,497,500,502,506],{"class":321,"line":322},[319,492,493],{"class":333},"Node\u003C",[319,495,496],{"class":325},"String",[319,498,499],{"class":333},"> head ",[319,501,397],{"class":325},[319,503,505],{"class":504},"sj4cs"," null",[319,507,508],{"class":333},";\n",[319,510,511,513,515,518,520,522],{"class":321,"line":343},[319,512,493],{"class":333},[319,514,496],{"class":325},[319,516,517],{"class":333},"> tail ",[319,519,397],{"class":325},[319,521,505],{"class":504},[319,523,508],{"class":333},[319,525,526],{"class":321,"line":353},[319,527,528],{"class":349},"\u002F\u002F The list is empty.\n",[195,530,532],{"id":531},"step-2-add-the-first-node-chicago","Step 2: Add the first node (\"Chicago\")",[60,534,536],{"className":313,"code":535,"language":315,"meta":68,"style":68},"head = new Node\u003C>(\"Chicago\");\ntail = head;\n",[15,537,538,557],{"__ignoreMap":68},[319,539,540,543,545,548,551,554],{"class":321,"line":322},[319,541,542],{"class":333},"head ",[319,544,397],{"class":325},[319,546,547],{"class":325}," new",[319,549,550],{"class":333}," Node\u003C>(",[319,552,472],{"class":553},"sZZnC",[319,555,556],{"class":333},");\n",[319,558,559,562,564],{"class":321,"line":343},[319,560,561],{"class":333},"tail ",[319,563,397],{"class":325},[319,565,566],{"class":333}," head;\n",[11,568,569],{},"After this:",[60,571,574],{"className":572,"code":573,"language":65},[63],"head → [Chicago | null] ← tail\n",[15,575,573],{"__ignoreMap":68},[11,577,578,579,581,582,584],{},"Both ",[15,580,433],{}," and ",[15,583,441],{}," point to the same single node.",[195,586,588],{"id":587},"step-3-add-the-second-node-denver","Step 3: Add the second node (\"Denver\")",[60,590,592],{"className":313,"code":591,"language":315,"meta":68,"style":68},"tail.next = new Node\u003C>(\"Denver\");\ntail = tail.next;\n",[15,593,594,609],{"__ignoreMap":68},[319,595,596,599,601,603,605,607],{"class":321,"line":322},[319,597,598],{"class":333},"tail.next ",[319,600,397],{"class":325},[319,602,547],{"class":325},[319,604,550],{"class":333},[319,606,475],{"class":553},[319,608,556],{"class":333},[319,610,611,613,615],{"class":321,"line":343},[319,612,561],{"class":333},[319,614,397],{"class":325},[319,616,617],{"class":333}," tail.next;\n",[11,619,620,621,623,624,626],{},"We attach the new node to the current tail's ",[15,622,448],{},", then move ",[15,625,441],{}," forward.",[60,628,631],{"className":629,"code":630,"language":65},[63],"head → [Chicago | next] → [Denver | null] ← tail\n",[15,632,630],{"__ignoreMap":68},[195,634,636],{"id":635},"step-4-add-the-third-node-dallas","Step 4: Add the third node (\"Dallas\")",[60,638,640],{"className":313,"code":639,"language":315,"meta":68,"style":68},"tail.next = new Node\u003C>(\"Dallas\");\ntail = tail.next;\n",[15,641,642,656],{"__ignoreMap":68},[319,643,644,646,648,650,652,654],{"class":321,"line":322},[319,645,598],{"class":333},[319,647,397],{"class":325},[319,649,547],{"class":325},[319,651,550],{"class":333},[319,653,478],{"class":553},[319,655,556],{"class":333},[319,657,658,660,662],{"class":321,"line":343},[319,659,561],{"class":333},[319,661,397],{"class":325},[319,663,617],{"class":333},[60,665,667],{"className":666,"code":419,"language":65},[63],[15,668,419],{"__ignoreMap":68},[11,670,671,672,674,675,677],{},"That's a linked list! Three nodes, chained together, with ",[15,673,433],{}," at the front and ",[15,676,441],{}," at the back.",[34,679,681],{"id":680},"_6-traversing-the-list","6. Traversing the List",[11,683,684,685,687,688,690,691,693],{},"To visit every node, we start at ",[15,686,433],{}," and follow ",[15,689,448],{}," pointers until we hit ",[15,692,452],{},":",[60,695,697],{"className":313,"code":696,"language":315,"meta":68,"style":68},"Node\u003CE> current = head;\nwhile (current != null) {\n    System.out.println(current.element);\n    current = current.next;  \u002F\u002F step forward\n}\n",[15,698,699,712,727,738,751],{"__ignoreMap":68},[319,700,701,703,705,708,710],{"class":321,"line":322},[319,702,493],{"class":333},[319,704,337],{"class":325},[319,706,707],{"class":333},"> current ",[319,709,397],{"class":325},[319,711,566],{"class":333},[319,713,714,717,720,723,725],{"class":321,"line":343},[319,715,716],{"class":325},"while",[319,718,719],{"class":333}," (current ",[319,721,722],{"class":325},"!=",[319,724,505],{"class":504},[319,726,388],{"class":333},[319,728,729,732,735],{"class":321,"line":353},[319,730,731],{"class":333},"    System.out.",[319,733,734],{"class":329},"println",[319,736,737],{"class":333},"(current.element);\n",[319,739,740,743,745,748],{"class":321,"line":367},[319,741,742],{"class":333},"    current ",[319,744,397],{"class":325},[319,746,747],{"class":333}," current.next;  ",[319,749,750],{"class":349},"\u002F\u002F step forward\n",[319,752,753],{"class":321,"line":373},[319,754,412],{"class":333},[11,756,757],{},"This is the bread-and-butter pattern of working with linked lists. Almost every operation uses some variant of this walk.",[34,759,761,762,765],{"id":760},"_7-building-our-own-mylinkedlist-class","7. Building Our Own ",[15,763,764],{},"MyLinkedList"," Class",[11,767,768,769,108,771,773,774,776],{},"Let's wrap all this up into a proper class. It'll keep track of ",[15,770,433],{},[15,772,441],{},", and ",[15,775,117],{},", and offer methods to add\u002Fremove elements:",[60,778,780],{"className":313,"code":779,"language":315,"meta":68,"style":68},"public class MyLinkedList\u003CE> {\n    private Node\u003CE> head;\n    private Node\u003CE> tail;\n    private int size;\n \n    \u002F\u002F ... methods below\n}\n",[15,781,782,799,812,823,833,837,842],{"__ignoreMap":68},[319,783,784,787,790,793,795,797],{"class":321,"line":322},[319,785,786],{"class":325},"public",[319,788,789],{"class":325}," class",[319,791,792],{"class":329}," MyLinkedList",[319,794,334],{"class":333},[319,796,337],{"class":325},[319,798,340],{"class":333},[319,800,801,804,807,809],{"class":321,"line":343},[319,802,803],{"class":325},"    private",[319,805,806],{"class":333}," Node\u003C",[319,808,337],{"class":325},[319,810,811],{"class":333},"> head;\n",[319,813,814,816,818,820],{"class":321,"line":353},[319,815,803],{"class":325},[319,817,806],{"class":333},[319,819,337],{"class":325},[319,821,822],{"class":333},"> tail;\n",[319,824,825,827,830],{"class":321,"line":367},[319,826,803],{"class":325},[319,828,829],{"class":325}," int",[319,831,832],{"class":333}," size;\n",[319,834,835],{"class":321,"line":373},[319,836,370],{"class":333},[319,838,839],{"class":321,"line":391},[319,840,841],{"class":349},"    \u002F\u002F ... methods below\n",[319,843,844],{"class":321,"line":403},[319,845,412],{"class":333},[11,847,848],{},"Now let's implement the core operations.",[195,850,852,855],{"id":851},"addfirste-e-add-to-the-head",[15,853,854],{},"addFirst(E e)"," — Add to the Head",[60,857,859],{"className":313,"code":858,"language":315,"meta":68,"style":68},"public void addFirst(E e) {\n    Node\u003CE> newNode = new Node\u003C>(e);\n    newNode.next = head;        \u002F\u002F new node points to current head\n    head = newNode;             \u002F\u002F new node becomes the head\n    size++;\n    if (tail == null)           \u002F\u002F if list was empty, new node is also tail\n        tail = head;\n}\n",[15,860,861,874,890,903,916,926,945,954],{"__ignoreMap":68},[319,862,863,865,868,871],{"class":321,"line":322},[319,864,786],{"class":325},[319,866,867],{"class":325}," void",[319,869,870],{"class":329}," addFirst",[319,872,873],{"class":333},"(E e) {\n",[319,875,876,878,880,883,885,887],{"class":321,"line":343},[319,877,356],{"class":333},[319,879,337],{"class":325},[319,881,882],{"class":333},"> newNode ",[319,884,397],{"class":325},[319,886,547],{"class":325},[319,888,889],{"class":333}," Node\u003C>(e);\n",[319,891,892,895,897,900],{"class":321,"line":353},[319,893,894],{"class":333},"    newNode.next ",[319,896,397],{"class":325},[319,898,899],{"class":333}," head;        ",[319,901,902],{"class":349},"\u002F\u002F new node points to current head\n",[319,904,905,908,910,913],{"class":321,"line":367},[319,906,907],{"class":333},"    head ",[319,909,397],{"class":325},[319,911,912],{"class":333}," newNode;             ",[319,914,915],{"class":349},"\u002F\u002F new node becomes the head\n",[319,917,918,921,924],{"class":321,"line":373},[319,919,920],{"class":333},"    size",[319,922,923],{"class":325},"++",[319,925,508],{"class":333},[319,927,928,931,934,937,939,942],{"class":321,"line":391},[319,929,930],{"class":325},"    if",[319,932,933],{"class":333}," (tail ",[319,935,936],{"class":325},"==",[319,938,505],{"class":504},[319,940,941],{"class":333},")           ",[319,943,944],{"class":349},"\u002F\u002F if list was empty, new node is also tail\n",[319,946,947,950,952],{"class":321,"line":403},[319,948,949],{"class":333},"        tail ",[319,951,397],{"class":325},[319,953,566],{"class":333},[319,955,956],{"class":321,"line":409},[319,957,412],{"class":333},[11,959,960,961,963,964,967,968,970],{},"The trick is to set the new node's ",[15,962,448],{}," ",[20,965,966],{},"before"," reassigning ",[15,969,433],{},". Otherwise we'd lose the rest of the list.",[195,972,974,977],{"id":973},"addlaste-e-add-to-the-tail",[15,975,976],{},"addLast(E e)"," — Add to the Tail",[60,979,981],{"className":313,"code":980,"language":315,"meta":68,"style":68},"public void addLast(E e) {\n    if (tail == null) {                  \u002F\u002F list is empty\n        head = tail = new Node\u003C>(e);\n    } else {\n        tail.next = new Node\u003C>(e);       \u002F\u002F old tail now points to new node\n        tail = tail.next;                \u002F\u002F new node becomes the tail\n    }\n    size++;\n}\n",[15,982,983,994,1010,1026,1037,1052,1064,1068,1076],{"__ignoreMap":68},[319,984,985,987,989,992],{"class":321,"line":322},[319,986,786],{"class":325},[319,988,867],{"class":325},[319,990,991],{"class":329}," addLast",[319,993,873],{"class":333},[319,995,996,998,1000,1002,1004,1007],{"class":321,"line":343},[319,997,930],{"class":325},[319,999,933],{"class":333},[319,1001,936],{"class":325},[319,1003,505],{"class":504},[319,1005,1006],{"class":333},") {                  ",[319,1008,1009],{"class":349},"\u002F\u002F list is empty\n",[319,1011,1012,1015,1017,1020,1022,1024],{"class":321,"line":353},[319,1013,1014],{"class":333},"        head ",[319,1016,397],{"class":325},[319,1018,1019],{"class":333}," tail ",[319,1021,397],{"class":325},[319,1023,547],{"class":325},[319,1025,889],{"class":333},[319,1027,1028,1031,1034],{"class":321,"line":367},[319,1029,1030],{"class":333},"    } ",[319,1032,1033],{"class":325},"else",[319,1035,1036],{"class":333}," {\n",[319,1038,1039,1042,1044,1046,1049],{"class":321,"line":373},[319,1040,1041],{"class":333},"        tail.next ",[319,1043,397],{"class":325},[319,1045,547],{"class":325},[319,1047,1048],{"class":333}," Node\u003C>(e);       ",[319,1050,1051],{"class":349},"\u002F\u002F old tail now points to new node\n",[319,1053,1054,1056,1058,1061],{"class":321,"line":391},[319,1055,949],{"class":333},[319,1057,397],{"class":325},[319,1059,1060],{"class":333}," tail.next;                ",[319,1062,1063],{"class":349},"\u002F\u002F new node becomes the tail\n",[319,1065,1066],{"class":321,"line":403},[319,1067,406],{"class":333},[319,1069,1070,1072,1074],{"class":321,"line":409},[319,1071,920],{"class":333},[319,1073,923],{"class":325},[319,1075,508],{"class":333},[319,1077,1079],{"class":321,"line":1078},9,[319,1080,412],{"class":333},[195,1082,1084,1087],{"id":1083},"addint-index-e-e-insert-at-a-specific-position",[15,1085,1086],{},"add(int index, E e)"," — Insert at a Specific Position",[11,1089,1090],{},"This is the most general case. We handle the easy cases first, then walk to the position:",[60,1092,1094],{"className":313,"code":1093,"language":315,"meta":68,"style":68},"public void add(int index, E e) {\n    if (index == 0) {\n        addFirst(e);\n    } else if (index >= size) {\n        addLast(e);\n    } else {\n        Node\u003CE> current = head;\n        for (int i = 1; i \u003C index; i++) {\n            current = current.next;       \u002F\u002F walk to the node BEFORE the index\n        }\n        Node\u003CE> temp = current.next;      \u002F\u002F remember what comes after\n        current.next = new Node\u003C>(e);     \u002F\u002F splice new node in\n        current.next.next = temp;         \u002F\u002F new node points to the rest\n        size++;\n    }\n}\n",[15,1095,1096,1114,1128,1136,1153,1160,1168,1181,1211,1224,1230,1248,1264,1278,1288,1293],{"__ignoreMap":68},[319,1097,1098,1100,1102,1105,1108,1111],{"class":321,"line":322},[319,1099,786],{"class":325},[319,1101,867],{"class":325},[319,1103,1104],{"class":329}," add",[319,1106,1107],{"class":333},"(",[319,1109,1110],{"class":325},"int",[319,1112,1113],{"class":333}," index, E e) {\n",[319,1115,1116,1118,1121,1123,1126],{"class":321,"line":343},[319,1117,930],{"class":325},[319,1119,1120],{"class":333}," (index ",[319,1122,936],{"class":325},[319,1124,1125],{"class":504}," 0",[319,1127,388],{"class":333},[319,1129,1130,1133],{"class":321,"line":353},[319,1131,1132],{"class":329},"        addFirst",[319,1134,1135],{"class":333},"(e);\n",[319,1137,1138,1140,1142,1145,1147,1150],{"class":321,"line":367},[319,1139,1030],{"class":333},[319,1141,1033],{"class":325},[319,1143,1144],{"class":325}," if",[319,1146,1120],{"class":333},[319,1148,1149],{"class":325},">=",[319,1151,1152],{"class":333}," size) {\n",[319,1154,1155,1158],{"class":321,"line":373},[319,1156,1157],{"class":329},"        addLast",[319,1159,1135],{"class":333},[319,1161,1162,1164,1166],{"class":321,"line":391},[319,1163,1030],{"class":333},[319,1165,1033],{"class":325},[319,1167,1036],{"class":333},[319,1169,1170,1173,1175,1177,1179],{"class":321,"line":403},[319,1171,1172],{"class":333},"        Node\u003C",[319,1174,337],{"class":325},[319,1176,707],{"class":333},[319,1178,397],{"class":325},[319,1180,566],{"class":333},[319,1182,1183,1186,1189,1191,1194,1196,1199,1202,1204,1207,1209],{"class":321,"line":409},[319,1184,1185],{"class":325},"        for",[319,1187,1188],{"class":333}," (",[319,1190,1110],{"class":325},[319,1192,1193],{"class":333}," i ",[319,1195,397],{"class":325},[319,1197,1198],{"class":504}," 1",[319,1200,1201],{"class":333},"; i ",[319,1203,334],{"class":325},[319,1205,1206],{"class":333}," index; i",[319,1208,923],{"class":325},[319,1210,388],{"class":333},[319,1212,1213,1216,1218,1221],{"class":321,"line":1078},[319,1214,1215],{"class":333},"            current ",[319,1217,397],{"class":325},[319,1219,1220],{"class":333}," current.next;       ",[319,1222,1223],{"class":349},"\u002F\u002F walk to the node BEFORE the index\n",[319,1225,1227],{"class":321,"line":1226},10,[319,1228,1229],{"class":333},"        }\n",[319,1231,1233,1235,1237,1240,1242,1245],{"class":321,"line":1232},11,[319,1234,1172],{"class":333},[319,1236,337],{"class":325},[319,1238,1239],{"class":333},"> temp ",[319,1241,397],{"class":325},[319,1243,1244],{"class":333}," current.next;      ",[319,1246,1247],{"class":349},"\u002F\u002F remember what comes after\n",[319,1249,1251,1254,1256,1258,1261],{"class":321,"line":1250},12,[319,1252,1253],{"class":333},"        current.next ",[319,1255,397],{"class":325},[319,1257,547],{"class":325},[319,1259,1260],{"class":333}," Node\u003C>(e);     ",[319,1262,1263],{"class":349},"\u002F\u002F splice new node in\n",[319,1265,1267,1270,1272,1275],{"class":321,"line":1266},13,[319,1268,1269],{"class":333},"        current.next.next ",[319,1271,397],{"class":325},[319,1273,1274],{"class":333}," temp;         ",[319,1276,1277],{"class":349},"\u002F\u002F new node points to the rest\n",[319,1279,1281,1284,1286],{"class":321,"line":1280},14,[319,1282,1283],{"class":333},"        size",[319,1285,923],{"class":325},[319,1287,508],{"class":333},[319,1289,1291],{"class":321,"line":1290},15,[319,1292,406],{"class":333},[319,1294,1296],{"class":321,"line":1295},16,[319,1297,412],{"class":333},[11,1299,1300,1301,1304,1305,1308,1309,1312],{},"The key idea: to insert ",[20,1302,1303],{},"at"," index ",[15,1306,1307],{},"i",", we stop ",[20,1310,1311],{},"one node before",". We then \"splice\" — break the existing link and reconnect on both sides of the new node.",[195,1314,1316,1319],{"id":1315},"removefirst-remove-the-head",[15,1317,1318],{},"removeFirst()"," — Remove the Head",[60,1321,1323],{"className":313,"code":1322,"language":315,"meta":68,"style":68},"public E removeFirst() {\n    if (size == 0) return null;\n    Node\u003CE> temp = head;\n    head = head.next;       \u002F\u002F second node becomes head\n    size--;\n    if (head == null) tail = null;   \u002F\u002F list is now empty\n    return temp.element;\n}\n",[15,1324,1325,1338,1359,1371,1383,1392,1416,1424],{"__ignoreMap":68},[319,1326,1327,1329,1332,1335],{"class":321,"line":322},[319,1328,786],{"class":325},[319,1330,1331],{"class":333}," E ",[319,1333,1334],{"class":329},"removeFirst",[319,1336,1337],{"class":333},"() {\n",[319,1339,1340,1342,1345,1347,1349,1352,1355,1357],{"class":321,"line":343},[319,1341,930],{"class":325},[319,1343,1344],{"class":333}," (size ",[319,1346,936],{"class":325},[319,1348,1125],{"class":504},[319,1350,1351],{"class":333},") ",[319,1353,1354],{"class":325},"return",[319,1356,505],{"class":504},[319,1358,508],{"class":333},[319,1360,1361,1363,1365,1367,1369],{"class":321,"line":353},[319,1362,356],{"class":333},[319,1364,337],{"class":325},[319,1366,1239],{"class":333},[319,1368,397],{"class":325},[319,1370,566],{"class":333},[319,1372,1373,1375,1377,1380],{"class":321,"line":367},[319,1374,907],{"class":333},[319,1376,397],{"class":325},[319,1378,1379],{"class":333}," head.next;       ",[319,1381,1382],{"class":349},"\u002F\u002F second node becomes head\n",[319,1384,1385,1387,1390],{"class":321,"line":373},[319,1386,920],{"class":333},[319,1388,1389],{"class":325},"--",[319,1391,508],{"class":333},[319,1393,1394,1396,1399,1401,1403,1406,1408,1410,1413],{"class":321,"line":391},[319,1395,930],{"class":325},[319,1397,1398],{"class":333}," (head ",[319,1400,936],{"class":325},[319,1402,505],{"class":504},[319,1404,1405],{"class":333},") tail ",[319,1407,397],{"class":325},[319,1409,505],{"class":504},[319,1411,1412],{"class":333},";   ",[319,1414,1415],{"class":349},"\u002F\u002F list is now empty\n",[319,1417,1418,1421],{"class":321,"line":403},[319,1419,1420],{"class":325},"    return",[319,1422,1423],{"class":333}," temp.element;\n",[319,1425,1426],{"class":321,"line":409},[319,1427,412],{"class":333},[195,1429,1431,1434],{"id":1430},"removelast-remove-the-tail",[15,1432,1433],{},"removeLast()"," — Remove the Tail",[11,1436,1437,1438,1441,1442,1444,1445,1447],{},"Trickier in a singly linked list! Why? Because to remove the tail, we need to update the ",[20,1439,1440],{},"second-to-last"," node's ",[15,1443,448],{}," to ",[15,1446,452],{},". But the tail doesn't have a \"previous\" pointer, so we have to walk from the head to find it.",[60,1449,1451],{"className":313,"code":1450,"language":315,"meta":68,"style":68},"public E removeLast() {\n    if (size == 0) return null;\n    if (size == 1) {                     \u002F\u002F only one node\n        Node\u003CE> temp = head;\n        head = tail = null;\n        size = 0;\n        return temp.element;\n    }\n    Node\u003CE> current = head;\n    for (int i = 0; i \u003C size - 2; i++)   \u002F\u002F stop at second-to-last\n        current = current.next;\n    Node\u003CE> temp = tail;\n    tail = current;\n    tail.next = null;\n    size--;\n    return temp.element;\n}\n",[15,1452,1453,1464,1482,1498,1510,1524,1535,1542,1546,1558,1597,1607,1620,1630,1641,1649,1655],{"__ignoreMap":68},[319,1454,1455,1457,1459,1462],{"class":321,"line":322},[319,1456,786],{"class":325},[319,1458,1331],{"class":333},[319,1460,1461],{"class":329},"removeLast",[319,1463,1337],{"class":333},[319,1465,1466,1468,1470,1472,1474,1476,1478,1480],{"class":321,"line":343},[319,1467,930],{"class":325},[319,1469,1344],{"class":333},[319,1471,936],{"class":325},[319,1473,1125],{"class":504},[319,1475,1351],{"class":333},[319,1477,1354],{"class":325},[319,1479,505],{"class":504},[319,1481,508],{"class":333},[319,1483,1484,1486,1488,1490,1492,1495],{"class":321,"line":353},[319,1485,930],{"class":325},[319,1487,1344],{"class":333},[319,1489,936],{"class":325},[319,1491,1198],{"class":504},[319,1493,1494],{"class":333},") {                     ",[319,1496,1497],{"class":349},"\u002F\u002F only one node\n",[319,1499,1500,1502,1504,1506,1508],{"class":321,"line":367},[319,1501,1172],{"class":333},[319,1503,337],{"class":325},[319,1505,1239],{"class":333},[319,1507,397],{"class":325},[319,1509,566],{"class":333},[319,1511,1512,1514,1516,1518,1520,1522],{"class":321,"line":373},[319,1513,1014],{"class":333},[319,1515,397],{"class":325},[319,1517,1019],{"class":333},[319,1519,397],{"class":325},[319,1521,505],{"class":504},[319,1523,508],{"class":333},[319,1525,1526,1529,1531,1533],{"class":321,"line":391},[319,1527,1528],{"class":333},"        size ",[319,1530,397],{"class":325},[319,1532,1125],{"class":504},[319,1534,508],{"class":333},[319,1536,1537,1540],{"class":321,"line":403},[319,1538,1539],{"class":325},"        return",[319,1541,1423],{"class":333},[319,1543,1544],{"class":321,"line":409},[319,1545,406],{"class":333},[319,1547,1548,1550,1552,1554,1556],{"class":321,"line":1078},[319,1549,356],{"class":333},[319,1551,337],{"class":325},[319,1553,707],{"class":333},[319,1555,397],{"class":325},[319,1557,566],{"class":333},[319,1559,1560,1563,1565,1567,1569,1571,1573,1575,1577,1580,1583,1586,1589,1591,1594],{"class":321,"line":1226},[319,1561,1562],{"class":325},"    for",[319,1564,1188],{"class":333},[319,1566,1110],{"class":325},[319,1568,1193],{"class":333},[319,1570,397],{"class":325},[319,1572,1125],{"class":504},[319,1574,1201],{"class":333},[319,1576,334],{"class":325},[319,1578,1579],{"class":333}," size ",[319,1581,1582],{"class":325},"-",[319,1584,1585],{"class":504}," 2",[319,1587,1588],{"class":333},"; i",[319,1590,923],{"class":325},[319,1592,1593],{"class":333},")   ",[319,1595,1596],{"class":349},"\u002F\u002F stop at second-to-last\n",[319,1598,1599,1602,1604],{"class":321,"line":1232},[319,1600,1601],{"class":333},"        current ",[319,1603,397],{"class":325},[319,1605,1606],{"class":333}," current.next;\n",[319,1608,1609,1611,1613,1615,1617],{"class":321,"line":1250},[319,1610,356],{"class":333},[319,1612,337],{"class":325},[319,1614,1239],{"class":333},[319,1616,397],{"class":325},[319,1618,1619],{"class":333}," tail;\n",[319,1621,1622,1625,1627],{"class":321,"line":1266},[319,1623,1624],{"class":333},"    tail ",[319,1626,397],{"class":325},[319,1628,1629],{"class":333}," current;\n",[319,1631,1632,1635,1637,1639],{"class":321,"line":1280},[319,1633,1634],{"class":333},"    tail.next ",[319,1636,397],{"class":325},[319,1638,505],{"class":504},[319,1640,508],{"class":333},[319,1642,1643,1645,1647],{"class":321,"line":1290},[319,1644,920],{"class":333},[319,1646,1389],{"class":325},[319,1648,508],{"class":333},[319,1650,1651,1653],{"class":321,"line":1295},[319,1652,1420],{"class":325},[319,1654,1423],{"class":333},[319,1656,1658],{"class":321,"line":1657},17,[319,1659,412],{"class":333},[11,1661,1662,1663,1666],{},"This is O(n) — not great. This is exactly the kind of problem that the ",[29,1664,1665],{},"doubly linked list"," (coming later) solves.",[195,1668,1670,1673],{"id":1669},"removeint-index-remove-at-a-specific-position",[15,1671,1672],{},"remove(int index)"," — Remove at a Specific Position",[60,1675,1677],{"className":313,"code":1676,"language":315,"meta":68,"style":68},"public E remove(int index) {\n    if (index \u003C 0 || index >= size) return null;\n    if (index == 0) return removeFirst();\n    if (index == size - 1) return removeLast();\n \n    Node\u003CE> previous = head;\n    for (int i = 1; i \u003C index; i++)\n        previous = previous.next;        \u002F\u002F stop just before the target\n    Node\u003CE> current = previous.next;     \u002F\u002F this is the node to remove\n    previous.next = current.next;        \u002F\u002F bypass it\n    size--;\n    return current.element;\n}\n",[15,1678,1679,1694,1720,1740,1763,1767,1780,1805,1818,1834,1847,1855,1862],{"__ignoreMap":68},[319,1680,1681,1683,1685,1687,1689,1691],{"class":321,"line":322},[319,1682,786],{"class":325},[319,1684,1331],{"class":333},[319,1686,111],{"class":329},[319,1688,1107],{"class":333},[319,1690,1110],{"class":325},[319,1692,1693],{"class":333}," index) {\n",[319,1695,1696,1698,1700,1702,1704,1707,1709,1711,1714,1716,1718],{"class":321,"line":343},[319,1697,930],{"class":325},[319,1699,1120],{"class":333},[319,1701,334],{"class":325},[319,1703,1125],{"class":504},[319,1705,1706],{"class":325}," ||",[319,1708,1304],{"class":333},[319,1710,1149],{"class":325},[319,1712,1713],{"class":333}," size) ",[319,1715,1354],{"class":325},[319,1717,505],{"class":504},[319,1719,508],{"class":333},[319,1721,1722,1724,1726,1728,1730,1732,1734,1737],{"class":321,"line":353},[319,1723,930],{"class":325},[319,1725,1120],{"class":333},[319,1727,936],{"class":325},[319,1729,1125],{"class":504},[319,1731,1351],{"class":333},[319,1733,1354],{"class":325},[319,1735,1736],{"class":329}," removeFirst",[319,1738,1739],{"class":333},"();\n",[319,1741,1742,1744,1746,1748,1750,1752,1754,1756,1758,1761],{"class":321,"line":367},[319,1743,930],{"class":325},[319,1745,1120],{"class":333},[319,1747,936],{"class":325},[319,1749,1579],{"class":333},[319,1751,1582],{"class":325},[319,1753,1198],{"class":504},[319,1755,1351],{"class":333},[319,1757,1354],{"class":325},[319,1759,1760],{"class":329}," removeLast",[319,1762,1739],{"class":333},[319,1764,1765],{"class":321,"line":373},[319,1766,370],{"class":333},[319,1768,1769,1771,1773,1776,1778],{"class":321,"line":391},[319,1770,356],{"class":333},[319,1772,337],{"class":325},[319,1774,1775],{"class":333},"> previous ",[319,1777,397],{"class":325},[319,1779,566],{"class":333},[319,1781,1782,1784,1786,1788,1790,1792,1794,1796,1798,1800,1802],{"class":321,"line":403},[319,1783,1562],{"class":325},[319,1785,1188],{"class":333},[319,1787,1110],{"class":325},[319,1789,1193],{"class":333},[319,1791,397],{"class":325},[319,1793,1198],{"class":504},[319,1795,1201],{"class":333},[319,1797,334],{"class":325},[319,1799,1206],{"class":333},[319,1801,923],{"class":325},[319,1803,1804],{"class":333},")\n",[319,1806,1807,1810,1812,1815],{"class":321,"line":409},[319,1808,1809],{"class":333},"        previous ",[319,1811,397],{"class":325},[319,1813,1814],{"class":333}," previous.next;        ",[319,1816,1817],{"class":349},"\u002F\u002F stop just before the target\n",[319,1819,1820,1822,1824,1826,1828,1831],{"class":321,"line":1078},[319,1821,356],{"class":333},[319,1823,337],{"class":325},[319,1825,707],{"class":333},[319,1827,397],{"class":325},[319,1829,1830],{"class":333}," previous.next;     ",[319,1832,1833],{"class":349},"\u002F\u002F this is the node to remove\n",[319,1835,1836,1839,1841,1844],{"class":321,"line":1226},[319,1837,1838],{"class":333},"    previous.next ",[319,1840,397],{"class":325},[319,1842,1843],{"class":333}," current.next;        ",[319,1845,1846],{"class":349},"\u002F\u002F bypass it\n",[319,1848,1849,1851,1853],{"class":321,"line":1232},[319,1850,920],{"class":333},[319,1852,1389],{"class":325},[319,1854,508],{"class":333},[319,1856,1857,1859],{"class":321,"line":1250},[319,1858,1420],{"class":325},[319,1860,1861],{"class":333}," current.element;\n",[319,1863,1864],{"class":321,"line":1266},[319,1865,412],{"class":333},[11,1867,1868],{},"Notice we orphan the removed node by skipping over it. Java's garbage collector will clean it up.",[34,1870,1872],{"id":1871},"_8-variations-singly-circular-doubly","8. Variations: Singly, Circular, Doubly",[11,1874,1875,1876,1879,1880,1882,1883,1885,1886,1889],{},"What we built above is called a ",[29,1877,1878],{},"singly linked list"," — each node has exactly one pointer (",[15,1881,448],{},"), and traversal can only go forward. To get to any node, you must start at ",[15,1884,433],{}," and walk one step at a time. It's ",[29,1887,1888],{},"not a direct access structure"," (unlike arrays).",[11,1891,1892],{},"There are a few common variations:",[195,1894,1896],{"id":1895},"circular-linked-list","Circular Linked List",[11,1898,1899,1900,963,1903,963,1907,1910,1911,1913],{},"Just like a singly linked list, except the ",[29,1901,1902],{},"last node's",[29,1904,1905],{},[15,1906,448],{},[29,1908,1909],{},"points back to the first node"," (instead of ",[15,1912,452],{},"). The list becomes a loop.",[60,1915,1918],{"className":1916,"code":1917,"language":65},[63],"head → [A | next] → [B | next] → [C | next] ┐\n        ↑___________________________________│\n",[15,1919,1917],{"__ignoreMap":68},[11,1921,1922],{},"Useful for things like round-robin schedulers or any \"cyclic\" data.",[195,1924,1926],{"id":1925},"doubly-linked-list","Doubly Linked List",[11,1928,1929,1930,1933,1934,1937],{},"Each node has ",[29,1931,1932],{},"two"," pointers: one to the next node, and one to the previous node. You can traverse the list in ",[20,1935,1936],{},"both"," directions.",[60,1939,1942],{"className":1940,"code":1941,"language":65},[63],"null ← [prev | A | next] ⇄ [prev | B | next] ⇄ [prev | C | next] → null\n",[15,1943,1941],{"__ignoreMap":68},[195,1945,1947],{"id":1946},"circular-doubly-linked-list","Circular Doubly Linked List",[11,1949,1950,1951,1953,1954,1957],{},"Doubly linked, plus the ends connect to each other (last's ",[15,1952,448],{}," → first, first's ",[15,1955,1956],{},"prev"," → last). A loop you can walk in either direction.",[11,1959,1960,1961,1963],{},"The rest of this post focuses on the doubly linked list, since it's the most useful variation in practice (it's actually what Java's built-in ",[15,1962,26],{}," class uses internally).",[34,1965,1967],{"id":1966},"_9-doubly-linked-lists-the-real-workhorse","9. Doubly Linked Lists: The Real Workhorse",[11,1969,46,1970,1972,1973,1975,1976,1979],{},[29,1971,1665],{}," is a linked structure where each node has two reference fields — one pointing to the ",[29,1974,448],{}," node, one pointing to the ",[29,1977,1978],{},"previous"," node.",[11,1981,1982],{},"Visually:",[60,1984,1987],{"className":1985,"code":1986,"language":65},[63],"        ┌──────┐ next  ┌──────┐ next  ┌──────┐\nnull  ← │  12  │  ⇄    │  99  │  ⇄    │  37  │ → null\n        └──────┘ prev  └──────┘ prev  └──────┘\n",[15,1988,1986],{"__ignoreMap":68},[11,1990,1991,1992,1995],{},"You can think of it as ",[29,1993,1994],{},"two singly linked lists"," layered on the same data — one going forward, one going backward.",[195,1997,1999],{"id":1998},"why-bother","Why bother?",[11,2001,2002],{},"The two-pointer design gives us two big wins:",[175,2004,2005,2015],{},[145,2006,2007,2010,2011,2014],{},[29,2008,2009],{},"Bidirectional traversal."," You can iterate forward ",[20,2012,2013],{},"or"," backward.",[145,2016,2017,2020,2021,2023,2024,2026],{},[29,2018,2019],{},"Simpler local modifications."," When inserting or deleting a node, you don't have to walk the list to find its \"previous\" — you already have it via ",[15,2022,1956],{},". This is what makes ",[15,2025,1433],{}," fast in a doubly linked list.",[195,2028,2030],{"id":2029},"the-trade-offs","The trade-offs",[11,2032,2033],{},"It's not all free:",[142,2035,2036,2039],{},[145,2037,2038],{},"Each node needs extra memory (one more pointer per node).",[145,2040,2041,2042,2045],{},"Insertion and deletion update more pointers (4 link updates instead of 2), so each operation does slightly more work — though it's still O(1) when you already have a reference to the node.\nFor most use cases, the benefits win. That's why Java's standard ",[15,2043,2044],{},"LinkedList\u003CE>"," is doubly linked.",[34,2047,2049],{"id":2048},"_10-building-a-doubly-linked-list","10. Building a Doubly Linked List",[195,2051,2053],{"id":2052},"the-node-class","The Node class",[60,2055,2057],{"className":313,"code":2056,"language":315,"meta":68,"style":68},"public class Node\u003CE> {\n    E element;\n    Node\u003CE> next;\n    Node\u003CE> prev;\n \n    public Node(E element, Node\u003CE> next, Node\u003CE> prev) {\n        this.element = element;\n        this.next = next;\n        this.prev = prev;\n    }\n \n    public Node(E element) {\n        this(element, null, null);\n    }\n}\n",[15,2058,2059,2073,2078,2087,2096,2100,2130,2143,2155,2167,2171,2175,2187,2202,2206],{"__ignoreMap":68},[319,2060,2061,2063,2065,2067,2069,2071],{"class":321,"line":322},[319,2062,786],{"class":325},[319,2064,789],{"class":325},[319,2066,330],{"class":329},[319,2068,334],{"class":333},[319,2070,337],{"class":325},[319,2072,340],{"class":333},[319,2074,2075],{"class":321,"line":343},[319,2076,2077],{"class":333},"    E element;\n",[319,2079,2080,2082,2084],{"class":321,"line":353},[319,2081,356],{"class":333},[319,2083,337],{"class":325},[319,2085,2086],{"class":333},"> next;\n",[319,2088,2089,2091,2093],{"class":321,"line":367},[319,2090,356],{"class":333},[319,2092,337],{"class":325},[319,2094,2095],{"class":333},"> prev;\n",[319,2097,2098],{"class":321,"line":373},[319,2099,370],{"class":333},[319,2101,2102,2104,2106,2108,2110,2113,2115,2118,2120,2122,2124,2126,2128],{"class":321,"line":391},[319,2103,376],{"class":325},[319,2105,330],{"class":329},[319,2107,381],{"class":333},[319,2109,303],{"class":384},[319,2111,2112],{"class":333},", Node\u003C",[319,2114,337],{"class":325},[319,2116,2117],{"class":333},"> ",[319,2119,448],{"class":384},[319,2121,2112],{"class":333},[319,2123,337],{"class":325},[319,2125,2117],{"class":333},[319,2127,1956],{"class":384},[319,2129,388],{"class":333},[319,2131,2132,2135,2138,2140],{"class":321,"line":403},[319,2133,2134],{"class":504},"        this",[319,2136,2137],{"class":333},".element ",[319,2139,397],{"class":325},[319,2141,2142],{"class":333}," element;\n",[319,2144,2145,2147,2150,2152],{"class":321,"line":409},[319,2146,2134],{"class":504},[319,2148,2149],{"class":333},".next ",[319,2151,397],{"class":325},[319,2153,2154],{"class":333}," next;\n",[319,2156,2157,2159,2162,2164],{"class":321,"line":1078},[319,2158,2134],{"class":504},[319,2160,2161],{"class":333},".prev ",[319,2163,397],{"class":325},[319,2165,2166],{"class":333}," prev;\n",[319,2168,2169],{"class":321,"line":1226},[319,2170,406],{"class":333},[319,2172,2173],{"class":321,"line":1232},[319,2174,370],{"class":333},[319,2176,2177,2179,2181,2183,2185],{"class":321,"line":1250},[319,2178,376],{"class":325},[319,2180,330],{"class":329},[319,2182,381],{"class":333},[319,2184,303],{"class":384},[319,2186,388],{"class":333},[319,2188,2189,2191,2194,2196,2198,2200],{"class":321,"line":1266},[319,2190,2134],{"class":504},[319,2192,2193],{"class":333},"(element, ",[319,2195,452],{"class":504},[319,2197,108],{"class":333},[319,2199,452],{"class":504},[319,2201,556],{"class":333},[319,2203,2204],{"class":321,"line":1280},[319,2205,406],{"class":333},[319,2207,2208],{"class":321,"line":1290},[319,2209,412],{"class":333},[195,2211,2213],{"id":2212},"the-list-class","The List class",[60,2215,2217],{"className":313,"code":2216,"language":315,"meta":68,"style":68},"public class DoublyLinkedList\u003CE> {\n    private Node\u003CE> head;\n    private Node\u003CE> tail;\n    private int size;\n \n    public DoublyLinkedList() {\n        size = 0;\n        this.head = null;\n        this.tail = null;\n    }\n \n    \u002F\u002F ... methods below\n}\n",[15,2218,2219,2234,2244,2254,2262,2266,2274,2284,2297,2310,2314,2318,2322],{"__ignoreMap":68},[319,2220,2221,2223,2225,2228,2230,2232],{"class":321,"line":322},[319,2222,786],{"class":325},[319,2224,789],{"class":325},[319,2226,2227],{"class":329}," DoublyLinkedList",[319,2229,334],{"class":333},[319,2231,337],{"class":325},[319,2233,340],{"class":333},[319,2235,2236,2238,2240,2242],{"class":321,"line":343},[319,2237,803],{"class":325},[319,2239,806],{"class":333},[319,2241,337],{"class":325},[319,2243,811],{"class":333},[319,2245,2246,2248,2250,2252],{"class":321,"line":353},[319,2247,803],{"class":325},[319,2249,806],{"class":333},[319,2251,337],{"class":325},[319,2253,822],{"class":333},[319,2255,2256,2258,2260],{"class":321,"line":367},[319,2257,803],{"class":325},[319,2259,829],{"class":325},[319,2261,832],{"class":333},[319,2263,2264],{"class":321,"line":373},[319,2265,370],{"class":333},[319,2267,2268,2270,2272],{"class":321,"line":391},[319,2269,376],{"class":325},[319,2271,2227],{"class":329},[319,2273,1337],{"class":333},[319,2275,2276,2278,2280,2282],{"class":321,"line":403},[319,2277,1528],{"class":333},[319,2279,397],{"class":325},[319,2281,1125],{"class":504},[319,2283,508],{"class":333},[319,2285,2286,2288,2291,2293,2295],{"class":321,"line":409},[319,2287,2134],{"class":504},[319,2289,2290],{"class":333},".head ",[319,2292,397],{"class":325},[319,2294,505],{"class":504},[319,2296,508],{"class":333},[319,2298,2299,2301,2304,2306,2308],{"class":321,"line":1078},[319,2300,2134],{"class":504},[319,2302,2303],{"class":333},".tail ",[319,2305,397],{"class":325},[319,2307,505],{"class":504},[319,2309,508],{"class":333},[319,2311,2312],{"class":321,"line":1226},[319,2313,406],{"class":333},[319,2315,2316],{"class":321,"line":1232},[319,2317,370],{"class":333},[319,2319,2320],{"class":321,"line":1250},[319,2321,841],{"class":349},[319,2323,2324],{"class":321,"line":1266},[319,2325,412],{"class":333},[34,2327,2329],{"id":2328},"_11-doubly-linked-list-insertion","11. Doubly Linked List: Insertion",[11,2331,2332],{},"There are three cases (same as singly linked):",[142,2334,2335,2344,2351],{},[145,2336,2337,2338,182,2341],{},"Insert at the ",[29,2339,2340],{},"beginning",[15,2342,2343],{},"addFirst(E)",[145,2345,2337,2346,182,2348],{},[29,2347,221],{},[15,2349,2350],{},"addLast(E)",[145,2352,2337,2353,182,2355],{},[29,2354,228],{},[15,2356,2357],{},"add(int index, E)",[195,2359,2361,2364],{"id":2360},"addfirste-element-insert-at-the-beginning",[15,2362,2363],{},"addFirst(E element)"," — Insert at the Beginning",[11,2366,2367,2368,2370,2371,2373],{},"Two changes are needed: the new node's ",[15,2369,448],{}," should point to the old head, and the old head's ",[15,2372,1956],{}," should point to the new node.",[60,2375,2377],{"className":313,"code":2376,"language":315,"meta":68,"style":68},"public void addFirst(E element) {\n    Node\u003CE> tmp = new Node\u003C>(element, head, null);\n    if (head != null) head.prev = tmp;     \u002F\u002F old head's prev now points back\n    head = tmp;                            \u002F\u002F new node is the head\n    if (tail == null) tail = tmp;          \u002F\u002F if list was empty, also the tail\n    size++;\n    System.out.println(\"adding: \" + element);\n}\n",[15,2378,2379,2390,2410,2431,2443,2463,2471,2488],{"__ignoreMap":68},[319,2380,2381,2383,2385,2387],{"class":321,"line":322},[319,2382,786],{"class":325},[319,2384,867],{"class":325},[319,2386,870],{"class":329},[319,2388,2389],{"class":333},"(E element) {\n",[319,2391,2392,2394,2396,2399,2401,2403,2406,2408],{"class":321,"line":343},[319,2393,356],{"class":333},[319,2395,337],{"class":325},[319,2397,2398],{"class":333},"> tmp ",[319,2400,397],{"class":325},[319,2402,547],{"class":325},[319,2404,2405],{"class":333}," Node\u003C>(element, head, ",[319,2407,452],{"class":504},[319,2409,556],{"class":333},[319,2411,2412,2414,2416,2418,2420,2423,2425,2428],{"class":321,"line":353},[319,2413,930],{"class":325},[319,2415,1398],{"class":333},[319,2417,722],{"class":325},[319,2419,505],{"class":504},[319,2421,2422],{"class":333},") head.prev ",[319,2424,397],{"class":325},[319,2426,2427],{"class":333}," tmp;     ",[319,2429,2430],{"class":349},"\u002F\u002F old head's prev now points back\n",[319,2432,2433,2435,2437,2440],{"class":321,"line":367},[319,2434,907],{"class":333},[319,2436,397],{"class":325},[319,2438,2439],{"class":333}," tmp;                            ",[319,2441,2442],{"class":349},"\u002F\u002F new node is the head\n",[319,2444,2445,2447,2449,2451,2453,2455,2457,2460],{"class":321,"line":373},[319,2446,930],{"class":325},[319,2448,933],{"class":333},[319,2450,936],{"class":325},[319,2452,505],{"class":504},[319,2454,1405],{"class":333},[319,2456,397],{"class":325},[319,2458,2459],{"class":333}," tmp;          ",[319,2461,2462],{"class":349},"\u002F\u002F if list was empty, also the tail\n",[319,2464,2465,2467,2469],{"class":321,"line":391},[319,2466,920],{"class":333},[319,2468,923],{"class":325},[319,2470,508],{"class":333},[319,2472,2473,2475,2477,2479,2482,2485],{"class":321,"line":403},[319,2474,731],{"class":333},[319,2476,734],{"class":329},[319,2478,1107],{"class":333},[319,2480,2481],{"class":553},"\"adding: \"",[319,2483,2484],{"class":325}," +",[319,2486,2487],{"class":333}," element);\n",[319,2489,2490],{"class":321,"line":409},[319,2491,412],{"class":333},[195,2493,2495,2498],{"id":2494},"addlaste-element-insert-at-the-end",[15,2496,2497],{},"addLast(E element)"," — Insert at the End",[11,2500,2501],{},"Mirror image:",[60,2503,2505],{"className":313,"code":2504,"language":315,"meta":68,"style":68},"public void addLast(E element) {\n    Node\u003CE> tmp = new Node\u003C>(element, null, tail);\n    if (tail != null) tail.next = tmp;     \u002F\u002F old tail's next points forward\n    tail = tmp;                            \u002F\u002F new node is the tail\n    if (head == null) head = tmp;          \u002F\u002F if list was empty, also the head\n    size++;\n    System.out.println(\"adding: \" + element);\n}\n",[15,2506,2507,2517,2537,2557,2568,2588,2596,2610],{"__ignoreMap":68},[319,2508,2509,2511,2513,2515],{"class":321,"line":322},[319,2510,786],{"class":325},[319,2512,867],{"class":325},[319,2514,991],{"class":329},[319,2516,2389],{"class":333},[319,2518,2519,2521,2523,2525,2527,2529,2532,2534],{"class":321,"line":343},[319,2520,356],{"class":333},[319,2522,337],{"class":325},[319,2524,2398],{"class":333},[319,2526,397],{"class":325},[319,2528,547],{"class":325},[319,2530,2531],{"class":333}," Node\u003C>(element, ",[319,2533,452],{"class":504},[319,2535,2536],{"class":333},", tail);\n",[319,2538,2539,2541,2543,2545,2547,2550,2552,2554],{"class":321,"line":353},[319,2540,930],{"class":325},[319,2542,933],{"class":333},[319,2544,722],{"class":325},[319,2546,505],{"class":504},[319,2548,2549],{"class":333},") tail.next ",[319,2551,397],{"class":325},[319,2553,2427],{"class":333},[319,2555,2556],{"class":349},"\u002F\u002F old tail's next points forward\n",[319,2558,2559,2561,2563,2565],{"class":321,"line":367},[319,2560,1624],{"class":333},[319,2562,397],{"class":325},[319,2564,2439],{"class":333},[319,2566,2567],{"class":349},"\u002F\u002F new node is the tail\n",[319,2569,2570,2572,2574,2576,2578,2581,2583,2585],{"class":321,"line":373},[319,2571,930],{"class":325},[319,2573,1398],{"class":333},[319,2575,936],{"class":325},[319,2577,505],{"class":504},[319,2579,2580],{"class":333},") head ",[319,2582,397],{"class":325},[319,2584,2459],{"class":333},[319,2586,2587],{"class":349},"\u002F\u002F if list was empty, also the head\n",[319,2589,2590,2592,2594],{"class":321,"line":391},[319,2591,920],{"class":333},[319,2593,923],{"class":325},[319,2595,508],{"class":333},[319,2597,2598,2600,2602,2604,2606,2608],{"class":321,"line":403},[319,2599,731],{"class":333},[319,2601,734],{"class":329},[319,2603,1107],{"class":333},[319,2605,2481],{"class":553},[319,2607,2484],{"class":325},[319,2609,2487],{"class":333},[319,2611,2612],{"class":321,"line":409},[319,2613,412],{"class":333},[195,2615,2617,2620],{"id":2616},"addint-index-e-element-insert-in-the-middle",[15,2618,2619],{},"add(int index, E element)"," — Insert in the Middle",[60,2622,2624],{"className":313,"code":2623,"language":315,"meta":68,"style":68},"public void add(int index, E element) {\n    if (index \u003C 0 || index > size)\n        throw new IndexOutOfBoundsException();\n \n    if (index == 0) {\n        addFirst(element);\n    } else if (index == size) {\n        addLast(element);\n    } else {\n        \u002F\u002F Walk to the node currently at the target index\n        Node\u003CE> temp = head;\n        for (int i = 0; i \u003C index; i++) {\n            temp = temp.next;\n        }\n        \u002F\u002F Create new node, sitting between temp.prev and temp\n        Node\u003CE> insert = new Node\u003C>(element, temp, temp.prev);\n        temp.prev.next = insert;   \u002F\u002F link 1: prev's next → new node\n        temp.prev = insert;        \u002F\u002F link 2: temp's prev → new node\n        size++;\n    }\n}\n",[15,2625,2626,2641,2661,2673,2677,2689,2696,2710,2716,2724,2729,2741,2765,2775,2779,2784,2800,2813,2827,2836,2841],{"__ignoreMap":68},[319,2627,2628,2630,2632,2634,2636,2638],{"class":321,"line":322},[319,2629,786],{"class":325},[319,2631,867],{"class":325},[319,2633,1104],{"class":329},[319,2635,1107],{"class":333},[319,2637,1110],{"class":325},[319,2639,2640],{"class":333}," index, E element) {\n",[319,2642,2643,2645,2647,2649,2651,2653,2655,2658],{"class":321,"line":343},[319,2644,930],{"class":325},[319,2646,1120],{"class":333},[319,2648,334],{"class":325},[319,2650,1125],{"class":504},[319,2652,1706],{"class":325},[319,2654,1304],{"class":333},[319,2656,2657],{"class":325},">",[319,2659,2660],{"class":333}," size)\n",[319,2662,2663,2666,2668,2671],{"class":321,"line":353},[319,2664,2665],{"class":325},"        throw",[319,2667,547],{"class":325},[319,2669,2670],{"class":329}," IndexOutOfBoundsException",[319,2672,1739],{"class":333},[319,2674,2675],{"class":321,"line":367},[319,2676,370],{"class":333},[319,2678,2679,2681,2683,2685,2687],{"class":321,"line":373},[319,2680,930],{"class":325},[319,2682,1120],{"class":333},[319,2684,936],{"class":325},[319,2686,1125],{"class":504},[319,2688,388],{"class":333},[319,2690,2691,2693],{"class":321,"line":391},[319,2692,1132],{"class":329},[319,2694,2695],{"class":333},"(element);\n",[319,2697,2698,2700,2702,2704,2706,2708],{"class":321,"line":403},[319,2699,1030],{"class":333},[319,2701,1033],{"class":325},[319,2703,1144],{"class":325},[319,2705,1120],{"class":333},[319,2707,936],{"class":325},[319,2709,1152],{"class":333},[319,2711,2712,2714],{"class":321,"line":409},[319,2713,1157],{"class":329},[319,2715,2695],{"class":333},[319,2717,2718,2720,2722],{"class":321,"line":1078},[319,2719,1030],{"class":333},[319,2721,1033],{"class":325},[319,2723,1036],{"class":333},[319,2725,2726],{"class":321,"line":1226},[319,2727,2728],{"class":349},"        \u002F\u002F Walk to the node currently at the target index\n",[319,2730,2731,2733,2735,2737,2739],{"class":321,"line":1232},[319,2732,1172],{"class":333},[319,2734,337],{"class":325},[319,2736,1239],{"class":333},[319,2738,397],{"class":325},[319,2740,566],{"class":333},[319,2742,2743,2745,2747,2749,2751,2753,2755,2757,2759,2761,2763],{"class":321,"line":1250},[319,2744,1185],{"class":325},[319,2746,1188],{"class":333},[319,2748,1110],{"class":325},[319,2750,1193],{"class":333},[319,2752,397],{"class":325},[319,2754,1125],{"class":504},[319,2756,1201],{"class":333},[319,2758,334],{"class":325},[319,2760,1206],{"class":333},[319,2762,923],{"class":325},[319,2764,388],{"class":333},[319,2766,2767,2770,2772],{"class":321,"line":1266},[319,2768,2769],{"class":333},"            temp ",[319,2771,397],{"class":325},[319,2773,2774],{"class":333}," temp.next;\n",[319,2776,2777],{"class":321,"line":1280},[319,2778,1229],{"class":333},[319,2780,2781],{"class":321,"line":1290},[319,2782,2783],{"class":349},"        \u002F\u002F Create new node, sitting between temp.prev and temp\n",[319,2785,2786,2788,2790,2793,2795,2797],{"class":321,"line":1295},[319,2787,1172],{"class":333},[319,2789,337],{"class":325},[319,2791,2792],{"class":333},"> insert ",[319,2794,397],{"class":325},[319,2796,547],{"class":325},[319,2798,2799],{"class":333}," Node\u003C>(element, temp, temp.prev);\n",[319,2801,2802,2805,2807,2810],{"class":321,"line":1657},[319,2803,2804],{"class":333},"        temp.prev.next ",[319,2806,397],{"class":325},[319,2808,2809],{"class":333}," insert;   ",[319,2811,2812],{"class":349},"\u002F\u002F link 1: prev's next → new node\n",[319,2814,2816,2819,2821,2824],{"class":321,"line":2815},18,[319,2817,2818],{"class":333},"        temp.prev ",[319,2820,397],{"class":325},[319,2822,2823],{"class":333}," insert;        ",[319,2825,2826],{"class":349},"\u002F\u002F link 2: temp's prev → new node\n",[319,2828,2830,2832,2834],{"class":321,"line":2829},19,[319,2831,1283],{"class":333},[319,2833,923],{"class":325},[319,2835,508],{"class":333},[319,2837,2839],{"class":321,"line":2838},20,[319,2840,406],{"class":333},[319,2842,2844],{"class":321,"line":2843},21,[319,2845,412],{"class":333},[11,2847,2848,2849,2851,2852,963,2855,2859,2860,2862,2863,2866,2867,2869],{},"The trick: when inserting at index ",[15,2850,1307],{},", the ",[29,2853,2854],{},"new node will become the node at index",[29,2856,2857],{},[15,2858,1307],{},", and the existing node at index ",[15,2861,1307],{}," shifts to index ",[15,2864,2865],{},"i+1",". So we walk to the existing node at index ",[15,2868,1307],{},", then splice the new one in just before it.",[11,2871,2872],{},"Four pointer updates happen here:",[175,2874,2875,2881,2886,2892],{},[145,2876,2877,2878,2880],{},"New node's ",[15,2879,448],{}," → existing node (set in constructor)",[145,2882,2877,2883,2885],{},[15,2884,1956],{}," → existing node's prev (set in constructor)",[145,2887,2888,2889,2891],{},"The previous node's ",[15,2890,448],{}," → new node",[145,2893,2894,2895,2891],{},"The existing node's ",[15,2896,1956],{},[34,2898,2900],{"id":2899},"_12-doubly-linked-list-traversal","12. Doubly Linked List: Traversal",[195,2902,2904],{"id":2903},"forward-same-as-singly-linked","Forward (same as singly linked):",[60,2906,2908],{"className":313,"code":2907,"language":315,"meta":68,"style":68},"public void iterateForward() {\n    System.out.println(\"iterating forward..\");\n    Node\u003CE> tmp = head;\n    while (tmp != null) {\n        System.out.print(tmp.element + \" \");\n        tmp = tmp.next;\n    }\n}\n",[15,2909,2910,2921,2934,2946,2960,2979,2989,2993],{"__ignoreMap":68},[319,2911,2912,2914,2916,2919],{"class":321,"line":322},[319,2913,786],{"class":325},[319,2915,867],{"class":325},[319,2917,2918],{"class":329}," iterateForward",[319,2920,1337],{"class":333},[319,2922,2923,2925,2927,2929,2932],{"class":321,"line":343},[319,2924,731],{"class":333},[319,2926,734],{"class":329},[319,2928,1107],{"class":333},[319,2930,2931],{"class":553},"\"iterating forward..\"",[319,2933,556],{"class":333},[319,2935,2936,2938,2940,2942,2944],{"class":321,"line":353},[319,2937,356],{"class":333},[319,2939,337],{"class":325},[319,2941,2398],{"class":333},[319,2943,397],{"class":325},[319,2945,566],{"class":333},[319,2947,2948,2951,2954,2956,2958],{"class":321,"line":367},[319,2949,2950],{"class":325},"    while",[319,2952,2953],{"class":333}," (tmp ",[319,2955,722],{"class":325},[319,2957,505],{"class":504},[319,2959,388],{"class":333},[319,2961,2962,2965,2968,2971,2974,2977],{"class":321,"line":373},[319,2963,2964],{"class":333},"        System.out.",[319,2966,2967],{"class":329},"print",[319,2969,2970],{"class":333},"(tmp.element ",[319,2972,2973],{"class":325},"+",[319,2975,2976],{"class":553}," \" \"",[319,2978,556],{"class":333},[319,2980,2981,2984,2986],{"class":321,"line":391},[319,2982,2983],{"class":333},"        tmp ",[319,2985,397],{"class":325},[319,2987,2988],{"class":333}," tmp.next;\n",[319,2990,2991],{"class":321,"line":403},[319,2992,406],{"class":333},[319,2994,2995],{"class":321,"line":409},[319,2996,412],{"class":333},[195,2998,3000],{"id":2999},"backward-this-is-where-doubly-linked-shines","Backward — this is where doubly linked shines:",[60,3002,3004],{"className":313,"code":3003,"language":315,"meta":68,"style":68},"public void iterateBackward() {\n    System.out.println(\"iterating backward..\");\n    Node\u003CE> tmp = tail;\n    while (tmp != null) {\n        System.out.println(tmp.element);\n        tmp = tmp.prev;\n    }\n}\n",[15,3005,3006,3017,3030,3042,3054,3063,3072,3076],{"__ignoreMap":68},[319,3007,3008,3010,3012,3015],{"class":321,"line":322},[319,3009,786],{"class":325},[319,3011,867],{"class":325},[319,3013,3014],{"class":329}," iterateBackward",[319,3016,1337],{"class":333},[319,3018,3019,3021,3023,3025,3028],{"class":321,"line":343},[319,3020,731],{"class":333},[319,3022,734],{"class":329},[319,3024,1107],{"class":333},[319,3026,3027],{"class":553},"\"iterating backward..\"",[319,3029,556],{"class":333},[319,3031,3032,3034,3036,3038,3040],{"class":321,"line":353},[319,3033,356],{"class":333},[319,3035,337],{"class":325},[319,3037,2398],{"class":333},[319,3039,397],{"class":325},[319,3041,1619],{"class":333},[319,3043,3044,3046,3048,3050,3052],{"class":321,"line":367},[319,3045,2950],{"class":325},[319,3047,2953],{"class":333},[319,3049,722],{"class":325},[319,3051,505],{"class":504},[319,3053,388],{"class":333},[319,3055,3056,3058,3060],{"class":321,"line":373},[319,3057,2964],{"class":333},[319,3059,734],{"class":329},[319,3061,3062],{"class":333},"(tmp.element);\n",[319,3064,3065,3067,3069],{"class":321,"line":391},[319,3066,2983],{"class":333},[319,3068,397],{"class":325},[319,3070,3071],{"class":333}," tmp.prev;\n",[319,3073,3074],{"class":321,"line":403},[319,3075,406],{"class":333},[319,3077,3078],{"class":321,"line":409},[319,3079,412],{"class":333},[11,3081,3082,3083,3085,3086,3088],{},"Start from ",[15,3084,441],{},", follow ",[15,3087,1956],{}," pointers. Impossible to do efficiently in a singly linked list.",[34,3090,3092],{"id":3091},"_13-doubly-linked-list-deletion","13. Doubly Linked List: Deletion",[11,3094,3095],{},"Three cases again.",[195,3097,3099,3101],{"id":3098},"removefirst-delete-the-head",[15,3100,1318],{}," — Delete the Head",[60,3103,3105],{"className":313,"code":3104,"language":315,"meta":68,"style":68},"public E removeFirst() {\n    if (size == 0) throw new NoSuchElementException();\n    Node\u003CE> tmp = head;\n    head = head.next;            \u002F\u002F second node becomes head\n    if (head != null) head.prev = null;   \u002F\u002F new head has no previous\n    size--;\n    System.out.println(\"deleted: \" + tmp.element);\n    return tmp.element;\n}\n",[15,3106,3107,3117,3139,3151,3162,3183,3191,3207,3214],{"__ignoreMap":68},[319,3108,3109,3111,3113,3115],{"class":321,"line":322},[319,3110,786],{"class":325},[319,3112,1331],{"class":333},[319,3114,1334],{"class":329},[319,3116,1337],{"class":333},[319,3118,3119,3121,3123,3125,3127,3129,3132,3134,3137],{"class":321,"line":343},[319,3120,930],{"class":325},[319,3122,1344],{"class":333},[319,3124,936],{"class":325},[319,3126,1125],{"class":504},[319,3128,1351],{"class":333},[319,3130,3131],{"class":325},"throw",[319,3133,547],{"class":325},[319,3135,3136],{"class":329}," NoSuchElementException",[319,3138,1739],{"class":333},[319,3140,3141,3143,3145,3147,3149],{"class":321,"line":353},[319,3142,356],{"class":333},[319,3144,337],{"class":325},[319,3146,2398],{"class":333},[319,3148,397],{"class":325},[319,3150,566],{"class":333},[319,3152,3153,3155,3157,3160],{"class":321,"line":367},[319,3154,907],{"class":333},[319,3156,397],{"class":325},[319,3158,3159],{"class":333}," head.next;            ",[319,3161,1382],{"class":349},[319,3163,3164,3166,3168,3170,3172,3174,3176,3178,3180],{"class":321,"line":373},[319,3165,930],{"class":325},[319,3167,1398],{"class":333},[319,3169,722],{"class":325},[319,3171,505],{"class":504},[319,3173,2422],{"class":333},[319,3175,397],{"class":325},[319,3177,505],{"class":504},[319,3179,1412],{"class":333},[319,3181,3182],{"class":349},"\u002F\u002F new head has no previous\n",[319,3184,3185,3187,3189],{"class":321,"line":391},[319,3186,920],{"class":333},[319,3188,1389],{"class":325},[319,3190,508],{"class":333},[319,3192,3193,3195,3197,3199,3202,3204],{"class":321,"line":403},[319,3194,731],{"class":333},[319,3196,734],{"class":329},[319,3198,1107],{"class":333},[319,3200,3201],{"class":553},"\"deleted: \"",[319,3203,2484],{"class":325},[319,3205,3206],{"class":333}," tmp.element);\n",[319,3208,3209,3211],{"class":321,"line":409},[319,3210,1420],{"class":325},[319,3212,3213],{"class":333}," tmp.element;\n",[319,3215,3216],{"class":321,"line":1078},[319,3217,412],{"class":333},[195,3219,3221,3223],{"id":3220},"removelast-delete-the-tail",[15,3222,1433],{}," — Delete the Tail",[11,3225,3226,3227,3230],{},"Much easier than in a singly linked list! No need to walk the list — ",[15,3228,3229],{},"tail.prev"," is right there:",[60,3232,3234],{"className":313,"code":3233,"language":315,"meta":68,"style":68},"public E removeLast() {\n    if (size == 0) throw new NoSuchElementException();\n    Node\u003CE> tmp = tail;\n    tail = tail.prev;            \u002F\u002F second-to-last becomes tail\n    if (tail != null) tail.next = null;\n    size--;\n    System.out.println(\"deleted: \" + tmp.element);\n    return tmp.element;\n}\n",[15,3235,3236,3246,3266,3278,3290,3308,3316,3330,3336],{"__ignoreMap":68},[319,3237,3238,3240,3242,3244],{"class":321,"line":322},[319,3239,786],{"class":325},[319,3241,1331],{"class":333},[319,3243,1461],{"class":329},[319,3245,1337],{"class":333},[319,3247,3248,3250,3252,3254,3256,3258,3260,3262,3264],{"class":321,"line":343},[319,3249,930],{"class":325},[319,3251,1344],{"class":333},[319,3253,936],{"class":325},[319,3255,1125],{"class":504},[319,3257,1351],{"class":333},[319,3259,3131],{"class":325},[319,3261,547],{"class":325},[319,3263,3136],{"class":329},[319,3265,1739],{"class":333},[319,3267,3268,3270,3272,3274,3276],{"class":321,"line":353},[319,3269,356],{"class":333},[319,3271,337],{"class":325},[319,3273,2398],{"class":333},[319,3275,397],{"class":325},[319,3277,1619],{"class":333},[319,3279,3280,3282,3284,3287],{"class":321,"line":367},[319,3281,1624],{"class":333},[319,3283,397],{"class":325},[319,3285,3286],{"class":333}," tail.prev;            ",[319,3288,3289],{"class":349},"\u002F\u002F second-to-last becomes tail\n",[319,3291,3292,3294,3296,3298,3300,3302,3304,3306],{"class":321,"line":373},[319,3293,930],{"class":325},[319,3295,933],{"class":333},[319,3297,722],{"class":325},[319,3299,505],{"class":504},[319,3301,2549],{"class":333},[319,3303,397],{"class":325},[319,3305,505],{"class":504},[319,3307,508],{"class":333},[319,3309,3310,3312,3314],{"class":321,"line":391},[319,3311,920],{"class":333},[319,3313,1389],{"class":325},[319,3315,508],{"class":333},[319,3317,3318,3320,3322,3324,3326,3328],{"class":321,"line":403},[319,3319,731],{"class":333},[319,3321,734],{"class":329},[319,3323,1107],{"class":333},[319,3325,3201],{"class":553},[319,3327,2484],{"class":325},[319,3329,3206],{"class":333},[319,3331,3332,3334],{"class":321,"line":409},[319,3333,1420],{"class":325},[319,3335,3213],{"class":333},[319,3337,3338],{"class":321,"line":1078},[319,3339,412],{"class":333},[11,3341,3342],{},"This is O(1) — instant. That's the doubly linked list paying its rent.",[195,3344,3346,3348],{"id":3345},"removeint-index-delete-in-the-middle",[15,3347,1672],{}," — Delete in the Middle",[60,3350,3352],{"className":313,"code":3351,"language":315,"meta":68,"style":68},"public E remove(int index) {\n    E element = null;\n    if (index \u003C 0 || index >= size)\n        throw new IndexOutOfBoundsException();\n \n    if (index == 0) {\n        return removeFirst();\n    } else if (index == size - 1) {\n        return removeLast();\n    } else {\n        Node\u003CE> temp = head;\n        for (int i = 0; i \u003C index; i++)\n            temp = temp.next;          \u002F\u002F walk to the target node\n        element = temp.element;\n \n        \u002F\u002F Splice it out\n        temp.next.prev = temp.prev;    \u002F\u002F next node's prev skips over temp\n        temp.prev.next = temp.next;    \u002F\u002F previous node's next skips over temp\n        temp.next = null;              \u002F\u002F clean up references\n        temp.prev = null;\n        size--;\n    }\n    return element;\n}\n",[15,3353,3354,3368,3379,3397,3407,3411,3423,3431,3451,3459,3467,3479,3503,3515,3523,3527,3532,3545,3557,3572,3582,3590,3595,3602],{"__ignoreMap":68},[319,3355,3356,3358,3360,3362,3364,3366],{"class":321,"line":322},[319,3357,786],{"class":325},[319,3359,1331],{"class":333},[319,3361,111],{"class":329},[319,3363,1107],{"class":333},[319,3365,1110],{"class":325},[319,3367,1693],{"class":333},[319,3369,3370,3373,3375,3377],{"class":321,"line":343},[319,3371,3372],{"class":333},"    E element ",[319,3374,397],{"class":325},[319,3376,505],{"class":504},[319,3378,508],{"class":333},[319,3380,3381,3383,3385,3387,3389,3391,3393,3395],{"class":321,"line":353},[319,3382,930],{"class":325},[319,3384,1120],{"class":333},[319,3386,334],{"class":325},[319,3388,1125],{"class":504},[319,3390,1706],{"class":325},[319,3392,1304],{"class":333},[319,3394,1149],{"class":325},[319,3396,2660],{"class":333},[319,3398,3399,3401,3403,3405],{"class":321,"line":367},[319,3400,2665],{"class":325},[319,3402,547],{"class":325},[319,3404,2670],{"class":329},[319,3406,1739],{"class":333},[319,3408,3409],{"class":321,"line":373},[319,3410,370],{"class":333},[319,3412,3413,3415,3417,3419,3421],{"class":321,"line":391},[319,3414,930],{"class":325},[319,3416,1120],{"class":333},[319,3418,936],{"class":325},[319,3420,1125],{"class":504},[319,3422,388],{"class":333},[319,3424,3425,3427,3429],{"class":321,"line":403},[319,3426,1539],{"class":325},[319,3428,1736],{"class":329},[319,3430,1739],{"class":333},[319,3432,3433,3435,3437,3439,3441,3443,3445,3447,3449],{"class":321,"line":409},[319,3434,1030],{"class":333},[319,3436,1033],{"class":325},[319,3438,1144],{"class":325},[319,3440,1120],{"class":333},[319,3442,936],{"class":325},[319,3444,1579],{"class":333},[319,3446,1582],{"class":325},[319,3448,1198],{"class":504},[319,3450,388],{"class":333},[319,3452,3453,3455,3457],{"class":321,"line":1078},[319,3454,1539],{"class":325},[319,3456,1760],{"class":329},[319,3458,1739],{"class":333},[319,3460,3461,3463,3465],{"class":321,"line":1226},[319,3462,1030],{"class":333},[319,3464,1033],{"class":325},[319,3466,1036],{"class":333},[319,3468,3469,3471,3473,3475,3477],{"class":321,"line":1232},[319,3470,1172],{"class":333},[319,3472,337],{"class":325},[319,3474,1239],{"class":333},[319,3476,397],{"class":325},[319,3478,566],{"class":333},[319,3480,3481,3483,3485,3487,3489,3491,3493,3495,3497,3499,3501],{"class":321,"line":1250},[319,3482,1185],{"class":325},[319,3484,1188],{"class":333},[319,3486,1110],{"class":325},[319,3488,1193],{"class":333},[319,3490,397],{"class":325},[319,3492,1125],{"class":504},[319,3494,1201],{"class":333},[319,3496,334],{"class":325},[319,3498,1206],{"class":333},[319,3500,923],{"class":325},[319,3502,1804],{"class":333},[319,3504,3505,3507,3509,3512],{"class":321,"line":1266},[319,3506,2769],{"class":333},[319,3508,397],{"class":325},[319,3510,3511],{"class":333}," temp.next;          ",[319,3513,3514],{"class":349},"\u002F\u002F walk to the target node\n",[319,3516,3517,3519,3521],{"class":321,"line":1280},[319,3518,394],{"class":333},[319,3520,397],{"class":325},[319,3522,1423],{"class":333},[319,3524,3525],{"class":321,"line":1290},[319,3526,370],{"class":333},[319,3528,3529],{"class":321,"line":1295},[319,3530,3531],{"class":349},"        \u002F\u002F Splice it out\n",[319,3533,3534,3537,3539,3542],{"class":321,"line":1657},[319,3535,3536],{"class":333},"        temp.next.prev ",[319,3538,397],{"class":325},[319,3540,3541],{"class":333}," temp.prev;    ",[319,3543,3544],{"class":349},"\u002F\u002F next node's prev skips over temp\n",[319,3546,3547,3549,3551,3554],{"class":321,"line":2815},[319,3548,2804],{"class":333},[319,3550,397],{"class":325},[319,3552,3553],{"class":333}," temp.next;    ",[319,3555,3556],{"class":349},"\u002F\u002F previous node's next skips over temp\n",[319,3558,3559,3562,3564,3566,3569],{"class":321,"line":2829},[319,3560,3561],{"class":333},"        temp.next ",[319,3563,397],{"class":325},[319,3565,505],{"class":504},[319,3567,3568],{"class":333},";              ",[319,3570,3571],{"class":349},"\u002F\u002F clean up references\n",[319,3573,3574,3576,3578,3580],{"class":321,"line":2838},[319,3575,2818],{"class":333},[319,3577,397],{"class":325},[319,3579,505],{"class":504},[319,3581,508],{"class":333},[319,3583,3584,3586,3588],{"class":321,"line":2843},[319,3585,1283],{"class":333},[319,3587,1389],{"class":325},[319,3589,508],{"class":333},[319,3591,3593],{"class":321,"line":3592},22,[319,3594,406],{"class":333},[319,3596,3598,3600],{"class":321,"line":3597},23,[319,3599,1420],{"class":325},[319,3601,2142],{"class":333},[319,3603,3605],{"class":321,"line":3604},24,[319,3606,412],{"class":333},[11,3608,3609,3610,693],{},"The two key lines are the ",[29,3611,3612],{},"splice",[142,3614,3615,3627],{},[145,3616,3617,3620,3621,3624,3625],{},[15,3618,3619],{},"temp.next.prev = temp.prev"," — the node after ",[15,3622,3623],{},"temp"," now points back to the node before ",[15,3626,3623],{},[145,3628,3629,3632,3633,3635,3636,3638,3639,3641],{},[15,3630,3631],{},"temp.prev.next = temp.next"," — the node before ",[15,3634,3623],{}," now points forward to the node after ",[15,3637,3623],{},"\nTogether, they \"skip over\" ",[15,3640,3623],{},", removing it from the chain.",[3643,3644],"hr",{},[34,3646,3648,3649,3652],{"id":3647},"_14-bonus-clear-wipe-the-list","14. Bonus: ",[15,3650,3651],{},"clear()"," — Wipe the List",[60,3654,3656],{"className":313,"code":3655,"language":315,"meta":68,"style":68},"public void clear() {\n    Node\u003CE> temp = head;\n    while (head != null) {\n        temp = head.next;\n        head.prev = head.next = null;   \u002F\u002F disconnect the current head\n        head = temp;                    \u002F\u002F advance\n    }\n    temp = null;\n    tail.prev = tail.next = null;\n    size = 0;\n}\n",[15,3657,3658,3669,3681,3693,3703,3722,3734,3738,3749,3765,3776],{"__ignoreMap":68},[319,3659,3660,3662,3664,3667],{"class":321,"line":322},[319,3661,786],{"class":325},[319,3663,867],{"class":325},[319,3665,3666],{"class":329}," clear",[319,3668,1337],{"class":333},[319,3670,3671,3673,3675,3677,3679],{"class":321,"line":343},[319,3672,356],{"class":333},[319,3674,337],{"class":325},[319,3676,1239],{"class":333},[319,3678,397],{"class":325},[319,3680,566],{"class":333},[319,3682,3683,3685,3687,3689,3691],{"class":321,"line":353},[319,3684,2950],{"class":325},[319,3686,1398],{"class":333},[319,3688,722],{"class":325},[319,3690,505],{"class":504},[319,3692,388],{"class":333},[319,3694,3695,3698,3700],{"class":321,"line":367},[319,3696,3697],{"class":333},"        temp ",[319,3699,397],{"class":325},[319,3701,3702],{"class":333}," head.next;\n",[319,3704,3705,3708,3710,3713,3715,3717,3719],{"class":321,"line":373},[319,3706,3707],{"class":333},"        head.prev ",[319,3709,397],{"class":325},[319,3711,3712],{"class":333}," head.next ",[319,3714,397],{"class":325},[319,3716,505],{"class":504},[319,3718,1412],{"class":333},[319,3720,3721],{"class":349},"\u002F\u002F disconnect the current head\n",[319,3723,3724,3726,3728,3731],{"class":321,"line":391},[319,3725,1014],{"class":333},[319,3727,397],{"class":325},[319,3729,3730],{"class":333}," temp;                    ",[319,3732,3733],{"class":349},"\u002F\u002F advance\n",[319,3735,3736],{"class":321,"line":403},[319,3737,406],{"class":333},[319,3739,3740,3743,3745,3747],{"class":321,"line":409},[319,3741,3742],{"class":333},"    temp ",[319,3744,397],{"class":325},[319,3746,505],{"class":504},[319,3748,508],{"class":333},[319,3750,3751,3754,3756,3759,3761,3763],{"class":321,"line":1078},[319,3752,3753],{"class":333},"    tail.prev ",[319,3755,397],{"class":325},[319,3757,3758],{"class":333}," tail.next ",[319,3760,397],{"class":325},[319,3762,505],{"class":504},[319,3764,508],{"class":333},[319,3766,3767,3770,3772,3774],{"class":321,"line":1226},[319,3768,3769],{"class":333},"    size ",[319,3771,397],{"class":325},[319,3773,1125],{"class":504},[319,3775,508],{"class":333},[319,3777,3778],{"class":321,"line":1232},[319,3779,412],{"class":333},[11,3781,3782],{},"We walk through and explicitly null out every pointer. This helps the garbage collector reclaim memory promptly.",[34,3784,3786],{"id":3785},"_15-wrapping-up","15. Wrapping Up",[11,3788,3789],{},"Here's the mental model to take with you:",[142,3791,3792,3798,3804,3813,3822,3832,3835],{},[145,3793,3794,3797],{},[29,3795,3796],{},"A linked list is a chain of nodes connected by references."," No contiguous memory required, no shifting needed when inserting in the middle.",[145,3799,3800,3803],{},[29,3801,3802],{},"Singly linked"," = forward pointers only. Cheap, but you can't go backward, and finding \"the previous node\" requires walking from the head.",[145,3805,3806,3809,3810,3812],{},[29,3807,3808],{},"Doubly linked"," = pointers in both directions. A bit more memory and slightly more work per update, but everything becomes simpler and ",[15,3811,1433],{}," becomes O(1).",[145,3814,3815,3818,3819,3821],{},[29,3816,3817],{},"Circular"," = the ends loop back. Useful for cyclic data.\nWhen should you reach for a linked list in real code? Honestly, in most everyday Java, ",[15,3820,17],{}," wins — it's faster in practice because modern CPUs love contiguous memory. But linked lists shine when:",[145,3823,3824,3825,3828,3829,3831],{},"You're frequently inserting\u002Fremoving at known positions (especially at both ends — use ",[15,3826,3827],{},"Deque","\u002F",[15,3830,26],{},")",[145,3833,3834],{},"You're building other data structures on top (queues, stacks, LRU caches, adjacency lists for graphs)",[145,3836,3837],{},"The teaching value alone: understanding linked lists makes trees, graphs, and many other structures click.",[11,3839,3840,3841,3844],{},"That last point is the real reason this is taught early. Linked lists are the gateway to thinking about ",[29,3842,3843],{},"structures made of nodes and references"," — and that mental model is everywhere in computer science.",[3846,3847,3848],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":68,"searchDepth":343,"depth":343,"links":3850},[3851,3852,3855,3856,3857,3863,3864,3879,3884,3888,3892,3900,3904,3912,3914],{"id":36,"depth":343,"text":37},{"id":133,"depth":343,"text":134,"children":3853},[3854],{"id":197,"depth":353,"text":198},{"id":255,"depth":343,"text":256},{"id":292,"depth":343,"text":293},{"id":465,"depth":343,"text":466,"children":3858},[3859,3860,3861,3862],{"id":482,"depth":353,"text":483},{"id":531,"depth":353,"text":532},{"id":587,"depth":353,"text":588},{"id":635,"depth":353,"text":636},{"id":680,"depth":343,"text":681},{"id":760,"depth":343,"text":3865,"children":3866},"7. Building Our Own MyLinkedList Class",[3867,3869,3871,3873,3875,3877],{"id":851,"depth":353,"text":3868},"addFirst(E e) — Add to the Head",{"id":973,"depth":353,"text":3870},"addLast(E e) — Add to the Tail",{"id":1083,"depth":353,"text":3872},"add(int index, E e) — Insert at a Specific Position",{"id":1315,"depth":353,"text":3874},"removeFirst() — Remove the Head",{"id":1430,"depth":353,"text":3876},"removeLast() — Remove the Tail",{"id":1669,"depth":353,"text":3878},"remove(int index) — Remove at a Specific Position",{"id":1871,"depth":343,"text":1872,"children":3880},[3881,3882,3883],{"id":1895,"depth":353,"text":1896},{"id":1925,"depth":353,"text":1926},{"id":1946,"depth":353,"text":1947},{"id":1966,"depth":343,"text":1967,"children":3885},[3886,3887],{"id":1998,"depth":353,"text":1999},{"id":2029,"depth":353,"text":2030},{"id":2048,"depth":343,"text":2049,"children":3889},[3890,3891],{"id":2052,"depth":353,"text":2053},{"id":2212,"depth":353,"text":2213},{"id":2328,"depth":343,"text":2329,"children":3893},[3894,3896,3898],{"id":2360,"depth":353,"text":3895},"addFirst(E element) — Insert at the Beginning",{"id":2494,"depth":353,"text":3897},"addLast(E element) — Insert at the End",{"id":2616,"depth":353,"text":3899},"add(int index, E element) — Insert in the Middle",{"id":2899,"depth":343,"text":2900,"children":3901},[3902,3903],{"id":2903,"depth":353,"text":2904},{"id":2999,"depth":353,"text":3000},{"id":3091,"depth":343,"text":3092,"children":3905},[3906,3908,3910],{"id":3098,"depth":353,"text":3907},"removeFirst() — Delete the Head",{"id":3220,"depth":353,"text":3909},"removeLast() — Delete the Tail",{"id":3345,"depth":353,"text":3911},"remove(int index) — Delete in the Middle",{"id":3647,"depth":343,"text":3913},"14. Bonus: clear() — Wipe the List",{"id":3785,"depth":343,"text":3786},"2026-05-13","If you've ever used ArrayList in Java and wondered what the other list — LinkedList — is doing differently, this post is for you. We're going to walk through what linked lists are, why they exist alongside arrays, and how to build one from scratch. Then we'll level up to doubly linked lists, which are a small twist on the idea with surprisingly nice properties.",false,"md",null,{},true,"\u002Fblog\u002FLinked-Lists-&-Doubly-Linked-Lists",{"title":5,"description":3916},{"loc":3922},"blog\u002FLinked-Lists-&-Doubly-Linked-Lists","X5It7DnQ1OY4lgsHR7NDVM9Apq6O2Ox5tcqCudDSxzA",116,{"id":3929,"extension":3930,"meta":3931,"series":3932,"stem":4042,"__hash__":4043},"series\u002Fseries.json","json",{},{"微積分教學":3933,"生活紀錄":3936,"Motor Control":3938,"生活隨筆":3952,"Motor learning":3956,"小兒物治":3974,"中風":3989,"平衡":4002,"Network Communication":4012,"CSA":4019,"機器學習":4025,"小腦":4029,"SCI脊髓損傷":4038},[3934,3935],"微積分隨筆-未完成版","2025數學回顧",[3937],"一個漂流到地球的故事",[3939,3940,3941,3942,3943,3944,3945,3946,3947,3948,3949,3950,3951],"控制自己-Be-water-my-friend","控制自己-Be-water-my-friend（二）","控制自己-Be-water-my-friend（三）","控制自己-Be-water-my-friend（四）","控制自己-Be-water-my-friend（五）","進階控制制制制","周圍理論學派（一）反射理論","周圍理論學派（二）階層理論","中樞理論學派（一）CPG","中樞理論學派（二）Motor-Program","模組理論","系統理論","動態模組理論",[3953,3954,3955],"你好，世界。","根本沒人在乎你的部落格","早安-午安-晚安",[3957,3958,3959,3960,3961,3962,3963,3964,3965,3966,3967,3968,3969,3970,3971,3972,3973],"動作學習（一）介紹","動作學習（二）form-of-learning","動作學習（三）Measurement-of-learning","動作學習（四）理論","動作學習（五）理論-2","動作學習（六）理論-3","動作學習（七）練習方式-1","動作學習（八）練習方式-2","動作學習（九）回饋-1","動作學習（十）回饋-2-擴增性(KR)","動作學習（十一）回饋-3-擴增性(KP)","動作學習（十一）回饋-4-(間隔+物理引導)","動作學習（十二）神經可塑性","動作學習（十二）神經可塑性2","動作學習（十三）臨床應用","動作學習（十四）記憶","動作學習（十五）影響表現的因素",[3975,3976,3977,3978,3979,3980,3981,3982,3983,3984,3985,3986,3987,3988],"腦性痲痺-CP","CP補充（一）","CP—Rood-&-Bobath","CP—Rood-&-Bobath（二）","Motor-Learning","Motor-Learning小兒（二）","Gait-analysis小兒（一）","Gait-analysis小兒（二）","小兒發展（一）","小兒發展（二）","小兒發展（三）","小兒發展（四）","小兒發展（五）","GMFCS",[3990,3991,3992,3993,3994,3995,3996,3997,3998,3999,4000,4001],"腦血管病變（CVA）（中風）(一)","CVA（二）","CVA（三）血管症候群-i","CVA（四）血管症候群-(ii)","CVA（四）","CVA（六）","CVA（七）評估-(i)","CVA（八）評估-(ii)","CVA（九）復健—手部-(i)","CVA（十）功能性走路","CVA（十一）功能性走路ii","CVA（十二）輔助用品",[4003,4004,4005,4006,4007,4008,4009,4010,4011],"平衡與前庭失調（一）","Balance（二）前庭覺-(i)","Balance（三）","Balance（四）評估","Balance（五）復健","Balance（六）功能恢復","Balance（七）前庭障礙","Balance（八）檢查","Balance（九）干預",[4013,4014,4015,4016,4017,4018],"Network-Communication,-Chapter-1","Network-Communication,-Chapter-2","Network-Communication,-Chapter-3","Network-Communication-Chapter-4","Network-Communications,-Chapter-5","Network-Communication,-Chapter-6",[4020,4021,4022,4023,4024],"Week-1-—-Introduction-to-Computer-Systems","Computer-Systems-Architecture-Understanding-Performance","A-Top-Level-View-of-Computer-Function-and-Interconnection","The-Memory-Hierarchy-Understanding-Cache-Memory","Internal-Memory-How-Your-Computer-Remembers-Things",[4026,4027,4028],"機器學習導論","資料前處理與迴歸分析","決策樹",[4030,4031,4032,4033,4034,4035,4036,4037],"小腦（一）","小腦（二）","小腦（三）功能","小腦（四）損傷","小腦（五）各功能障礙","小腦（六）評估","小腦（七）評估(ii)","小腦（八）治療",[4039,4040,4041],"脊髓損傷SCI（一）","SCI（二）受傷機制——創傷性（頸椎）","SCI（三）受傷機制--ii","series","OrQkztaCQ8PCQ3c33l2XQ4ZKtA6mZbR3LOKgfR0KR_M",[4045,4064,4084,4103,4120,4137,4152,4169,4187,4209],{"id":4046,"title":4047,"avatar":4048,"banner":3919,"bio":4049,"body":4050,"description":68,"extension":3918,"meta":4054,"name":4047,"navigation":3921,"path":4055,"seo":4056,"sitemap":4057,"social":4058,"stem":4062,"__hash__":4063},"authors\u002Fauthors\u002Fautomata.md","Automata","\u002Fimages\u002Fuploads\u002Fnier-automata-2b.jpg","一隻吐司天喵，漂浮在銀河星辰中",{"type":8,"value":4051,"toc":4052},[],{"title":68,"searchDepth":343,"depth":343,"links":4053},[],{},"\u002Fauthors\u002Fautomata",{"description":68},{"loc":4055},{"website":4059,"twitter":4060,"github":4061},"https:\u002F\u002Freurl.cc\u002FWOeM29","https:\u002F\u002Freurl.cc\u002FLnvLEy","https:\u002F\u002Fgithub.com\u002FAutomata-0","authors\u002Fautomata","IkVbO2zA7revgYq624iVWpSZQUyMmWa82tw_EbWXViE",{"id":4065,"title":4066,"avatar":4067,"banner":4068,"bio":4069,"body":4070,"description":68,"extension":3918,"meta":4074,"name":4075,"navigation":3921,"path":4076,"seo":4077,"sitemap":4078,"social":4079,"stem":4082,"__hash__":4083},"authors\u002Fauthors\u002Fchinono.md","Chinono","\u002Fimages\u002Fuploads\u002F103467998_p0 copy.png","\u002Fimages\u002Fbackground_light.jpg","我不是女生！",{"type":8,"value":4071,"toc":4072},[],{"title":68,"searchDepth":343,"depth":343,"links":4073},[],{},"七糯糯","\u002Fauthors\u002Fchinono",{"description":68},{"loc":4076},{"github":4080,"twitter":68,"website":4081},"https:\u002F\u002Fgithub.com\u002FChinHongTan","https:\u002F\u002Fchinono.dev","authors\u002Fchinono","jj1J9mFh3InZFL6XtCzGBQ5jPip0EwBDE3mjGvnN6jE",{"id":4085,"title":4086,"avatar":4087,"banner":4088,"bio":4089,"body":4090,"description":68,"extension":3918,"meta":4094,"name":4095,"navigation":3921,"path":4096,"seo":4097,"sitemap":4098,"social":4099,"stem":4101,"__hash__":4102},"authors\u002Fauthors\u002Fhibiki12141132.md","Hibiki12141132","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F265822020?v=4","\u002Fimages\u002Fuploads\u002F1773978423557-___.jpg","享受著知識強姦大腦的過程 (內文含個人發癲 不要再意)",{"type":8,"value":4091,"toc":4092},[],{"title":68,"searchDepth":343,"depth":343,"links":4093},[],{},"HiBiKi","\u002Fauthors\u002Fhibiki12141132",{"description":68},{"loc":4096},{"github":4100,"twitter":68},"https:\u002F\u002Fgithub.com\u002FHiBiKi12141132","authors\u002Fhibiki12141132","dbRnKEcYeCH_faD8R7AUmPPcwgc26s_fR4Q_lu4qtA4",{"id":4104,"title":4105,"avatar":4106,"banner":3919,"bio":4107,"body":4108,"description":68,"extension":3918,"meta":4112,"name":4105,"navigation":3921,"path":4113,"seo":4114,"sitemap":4115,"social":4116,"stem":4118,"__hash__":4119},"authors\u002Fauthors\u002Fmahiro.md","Mahiro","https:\u002F\u002Ftruth.bahamut.com.tw\u002Fs01\u002F202601\u002F2a29b047d341f840b2ce89f7d65b2ba3.JPG","一個致力於逃離新竹的電機系小雜魚",{"type":8,"value":4109,"toc":4110},[],{"title":68,"searchDepth":343,"depth":343,"links":4111},[],{},"\u002Fauthors\u002Fmahiro",{"description":68},{"loc":4113},{"github":4117},"https:\u002F\u002Fgithub.com\u002Fwifekurumi","authors\u002Fmahiro","b435tdWu9eXUf06WroCge0I405cqA0FhLlUUhoPk14k",{"id":4121,"title":4122,"avatar":4123,"banner":3919,"bio":4124,"body":4125,"description":68,"extension":3918,"meta":4129,"name":4122,"navigation":3921,"path":4130,"seo":4131,"sitemap":4132,"social":4133,"stem":4135,"__hash__":4136},"authors\u002Fauthors\u002Fosborrrrn.md","Osborrrrn","\u002Fimages\u002Fuploads\u002Frectangle_large_type_2_c516437ed713e5de1f7d2dca8a20cd81.jpg","別人笑我太瘋癲，我笑他人看不穿。\n不見五陵豪傑墓，無花無酒鋤就田",{"type":8,"value":4126,"toc":4127},[],{"title":68,"searchDepth":343,"depth":343,"links":4128},[],{},"\u002Fauthors\u002Fosborrrrn",{"description":68},{"loc":4130},{"github":4134},"https:\u002F\u002Fgithub.com\u002FOsborrrrn","authors\u002Fosborrrrn","w6VWZKPUwvXn5i7MKXOpU2Jeqr3BrdTKVCeDOF2jZlU",{"id":4138,"title":4139,"avatar":3919,"banner":3919,"bio":4140,"body":4141,"description":68,"extension":3918,"meta":4145,"name":4139,"navigation":3921,"path":4146,"seo":4147,"sitemap":4148,"social":4149,"stem":4150,"__hash__":4151},"authors\u002Fauthors\u002F法法.md","法法","123",{"type":8,"value":4142,"toc":4143},[],{"title":68,"searchDepth":343,"depth":343,"links":4144},[],{},"\u002Fauthors\u002F法法",{"description":68},{"loc":4146},{"github":68},"authors\u002F法法","o5pdVuPCfTmhkDCpvgy4YmAP0CGdvFluPvjhgvQVbsI",{"id":4153,"title":4154,"avatar":4155,"banner":3919,"bio":4156,"body":4157,"description":68,"extension":3918,"meta":4161,"name":4154,"navigation":3921,"path":4162,"seo":4163,"sitemap":4164,"social":4165,"stem":4167,"__hash__":4168},"authors\u002Fauthors\u002F灰海獅.md","灰海獅","\u002Fimages\u002Fuploads\u002Fimg_3279.jpeg","守夜人",{"type":8,"value":4158,"toc":4159},[],{"title":68,"searchDepth":343,"depth":343,"links":4160},[],{},"\u002Fauthors\u002F灰海獅",{"description":68},{"loc":4162},{"github":4166},"https:\u002F\u002Fgithub.com\u002Fyuiri333","authors\u002F灰海獅","iZoSIFbQdS-6v3LiK1txgxnIMKy-d2CyZXQk9CMua_s",{"id":4170,"title":4171,"avatar":4172,"banner":4173,"bio":4174,"body":4175,"description":68,"extension":3918,"meta":4179,"name":4171,"navigation":3921,"path":4180,"seo":4181,"sitemap":4182,"social":4183,"stem":4185,"__hash__":4186},"authors\u002Fauthors\u002F花夜.md","花夜","\u002Fimages\u002Fuploads\u002F1772719470518-791_20260218161129.png","\u002Fimages\u002Fuploads\u002Fimg_2446.png","無論你身在何處，我都會在這裡等你",{"type":8,"value":4176,"toc":4177},[],{"title":68,"searchDepth":343,"depth":343,"links":4178},[],{},"\u002Fauthors\u002F花夜",{"description":68},{"loc":4180},{"github":4184,"twitter":68},"https:\u002F\u002Fgithub.com\u002Fflowernight0709","authors\u002F花夜","a7jeQiF_JkawgYIR-aYSGceJdDP6Z-OWydsICvgSIzs",{"id":4188,"title":4189,"avatar":4190,"banner":4191,"bio":4192,"body":4193,"description":4197,"extension":3918,"meta":4200,"name":4189,"navigation":3921,"path":4201,"seo":4202,"sitemap":4203,"social":4204,"stem":4207,"__hash__":4208},"authors\u002Fauthors\u002F輝月.md","輝月","\u002Fimages\u002Fuploads\u002Ffb_img_1771085634823.jpg","\u002Fimages\u002Fuploads\u002Fimg_1751.jpg","天下布魔好好玩",{"type":8,"value":4194,"toc":4198},[4195],[11,4196,4197],{},"準大學生，目前正在製作TFR模組",{"title":68,"searchDepth":343,"depth":343,"links":4199},[],{},"\u002Fauthors\u002F輝月",{"description":4197},{"loc":4201},{"twitter":4205,"github":4206},"https:\u002F\u002Fx.com\u002Fhuiyue945","https:\u002F\u002Fgithub.com\u002Fhuiyueyea","authors\u002F輝月","koUocBihphDy3453-nAcolM7JJYwI7UMBpVkf1JQrMQ",{"id":4210,"title":4211,"avatar":4212,"banner":3919,"bio":4213,"body":4214,"description":4218,"extension":3918,"meta":4231,"name":4211,"navigation":3921,"path":4232,"seo":4233,"sitemap":4234,"social":4235,"stem":4237,"__hash__":4238},"authors\u002Fauthors\u002F阿西狄亞.md","阿西狄亞","\u002Fimages\u002Fuploads\u002Fimg_20251215_121849_589.jpg","君は実に馬鹿だな",{"type":8,"value":4215,"toc":4229},[4216,4219],[11,4217,4218],{},"我是阿西狄亞，阿西狄亞的阿，阿西狄亞的西，阿西狄亞的狄，阿西狄亞的亞，你可以叫我阿西。",[11,4220,4221,4224,4225,4228],{},[29,4222,4223],{},"我說的所有事情都抱有極度主觀的看法以及意見","，如果你有其他想法，",[29,4226,4227],{},"你是對的","。",{"title":68,"searchDepth":343,"depth":343,"links":4230},[],{},"\u002Fauthors\u002F阿西狄亞",{"description":4218},{"loc":4232},{"github":4236},"https:\u002F\u002Fgithub.com\u002FAcedia0130","authors\u002F阿西狄亞","q5ECEDl8-0Y33tPck0lYZnzPjFdJkrOnBN7HkAO3pls",[],[4241,4250,4259,4268,4277,4286,4295,4304,4313,4324],{"id":4046,"title":4047,"avatar":4048,"banner":3919,"bio":4049,"body":4242,"description":68,"extension":3918,"meta":4246,"name":4047,"navigation":3921,"path":4055,"seo":4247,"sitemap":4248,"social":4249,"stem":4062,"__hash__":4063},{"type":8,"value":4243,"toc":4244},[],{"title":68,"searchDepth":343,"depth":343,"links":4245},[],{},{"description":68},{"loc":4055},{"website":4059,"twitter":4060,"github":4061},{"id":4065,"title":4066,"avatar":4067,"banner":4068,"bio":4069,"body":4251,"description":68,"extension":3918,"meta":4255,"name":4075,"navigation":3921,"path":4076,"seo":4256,"sitemap":4257,"social":4258,"stem":4082,"__hash__":4083},{"type":8,"value":4252,"toc":4253},[],{"title":68,"searchDepth":343,"depth":343,"links":4254},[],{},{"description":68},{"loc":4076},{"github":4080,"twitter":68,"website":4081},{"id":4085,"title":4086,"avatar":4087,"banner":4088,"bio":4089,"body":4260,"description":68,"extension":3918,"meta":4264,"name":4095,"navigation":3921,"path":4096,"seo":4265,"sitemap":4266,"social":4267,"stem":4101,"__hash__":4102},{"type":8,"value":4261,"toc":4262},[],{"title":68,"searchDepth":343,"depth":343,"links":4263},[],{},{"description":68},{"loc":4096},{"github":4100,"twitter":68},{"id":4104,"title":4105,"avatar":4106,"banner":3919,"bio":4107,"body":4269,"description":68,"extension":3918,"meta":4273,"name":4105,"navigation":3921,"path":4113,"seo":4274,"sitemap":4275,"social":4276,"stem":4118,"__hash__":4119},{"type":8,"value":4270,"toc":4271},[],{"title":68,"searchDepth":343,"depth":343,"links":4272},[],{},{"description":68},{"loc":4113},{"github":4117},{"id":4121,"title":4122,"avatar":4123,"banner":3919,"bio":4124,"body":4278,"description":68,"extension":3918,"meta":4282,"name":4122,"navigation":3921,"path":4130,"seo":4283,"sitemap":4284,"social":4285,"stem":4135,"__hash__":4136},{"type":8,"value":4279,"toc":4280},[],{"title":68,"searchDepth":343,"depth":343,"links":4281},[],{},{"description":68},{"loc":4130},{"github":4134},{"id":4138,"title":4139,"avatar":3919,"banner":3919,"bio":4140,"body":4287,"description":68,"extension":3918,"meta":4291,"name":4139,"navigation":3921,"path":4146,"seo":4292,"sitemap":4293,"social":4294,"stem":4150,"__hash__":4151},{"type":8,"value":4288,"toc":4289},[],{"title":68,"searchDepth":343,"depth":343,"links":4290},[],{},{"description":68},{"loc":4146},{"github":68},{"id":4153,"title":4154,"avatar":4155,"banner":3919,"bio":4156,"body":4296,"description":68,"extension":3918,"meta":4300,"name":4154,"navigation":3921,"path":4162,"seo":4301,"sitemap":4302,"social":4303,"stem":4167,"__hash__":4168},{"type":8,"value":4297,"toc":4298},[],{"title":68,"searchDepth":343,"depth":343,"links":4299},[],{},{"description":68},{"loc":4162},{"github":4166},{"id":4170,"title":4171,"avatar":4172,"banner":4173,"bio":4174,"body":4305,"description":68,"extension":3918,"meta":4309,"name":4171,"navigation":3921,"path":4180,"seo":4310,"sitemap":4311,"social":4312,"stem":4185,"__hash__":4186},{"type":8,"value":4306,"toc":4307},[],{"title":68,"searchDepth":343,"depth":343,"links":4308},[],{},{"description":68},{"loc":4180},{"github":4184,"twitter":68},{"id":4188,"title":4189,"avatar":4190,"banner":4191,"bio":4192,"body":4314,"description":4197,"extension":3918,"meta":4320,"name":4189,"navigation":3921,"path":4201,"seo":4321,"sitemap":4322,"social":4323,"stem":4207,"__hash__":4208},{"type":8,"value":4315,"toc":4318},[4316],[11,4317,4197],{},{"title":68,"searchDepth":343,"depth":343,"links":4319},[],{},{"description":4197},{"loc":4201},{"twitter":4205,"github":4206},{"id":4210,"title":4211,"avatar":4212,"banner":3919,"bio":4213,"body":4325,"description":4218,"extension":3918,"meta":4337,"name":4211,"navigation":3921,"path":4232,"seo":4338,"sitemap":4339,"social":4340,"stem":4237,"__hash__":4238},{"type":8,"value":4326,"toc":4335},[4327,4329],[11,4328,4218],{},[11,4330,4331,4224,4333,4228],{},[29,4332,4223],{},[29,4334,4227],{},{"title":68,"searchDepth":343,"depth":343,"links":4336},[],{},{"description":4218},{"loc":4232},{"github":4236},1778690569794]