[{"data":1,"prerenderedAt":2852},["ShallowReactive",2],{"\u002Fblog\u002FQueues":3,"post-count":2438,"series-global-data":2439,"authors-all":2555,"series-sidebar-none":2750,"sidebar-authors":2751},{"id":4,"title":5,"author":6,"body":7,"date":2426,"description":2427,"draft":2428,"edited_at":2426,"extension":2429,"featured_image":2430,"meta":2431,"navigation":2432,"path":2433,"pinned":2428,"seo":2434,"sitemap":2435,"stem":2436,"tags":2430,"__hash__":2437},"blog\u002Fblog\u002FQueues.md","Queues","chinono",{"type":8,"value":9,"toc":2395},"minimark",[10,23,26,31,34,45,48,67,74,78,89,95,98,143,147,150,209,231,236,247,251,255,265,268,278,307,313,323,326,333,340,363,374,387,401,407,420,428,431,670,673,717,721,865,876,880,883,886,893,905,919,923,934,937,944,950,953,966,973,1095,1126,1130,1133,1169,1173,1556,1562,1566,1573,1583,1830,1839,2064,2067,2073,2084,2124,2128,2131,2169,2172,2205,2209,2220,2249,2374,2377,2381,2384,2391],[11,12,13,14,18,19,22],"p",{},"If you've ever stood in line at a bubble tea shop, you already understand a ",[15,16,17],"strong",{},"queue",". That's basically the whole idea — but in code, this simple concept turns into one of the most useful data structures you'll meet. In this post we'll walk through what a queue is, how to implement one in Java, and then level it up into a ",[15,20,21],{},"priority queue",".",[11,24,25],{},"This is written for someone seeing it for the first time, so I won't assume much beyond \"you've written a few Java classes.\"",[27,28,30],"h2",{"id":29},"_1-the-mental-model","1. The mental model",[11,32,33],{},"Picture a checkout line at the supermarket:",[35,36,41],"pre",{"className":37,"code":39,"language":40},[38],"language-text","  front                                 rear\n   ↓                                     ↓\n [ A ] ← [ B ] ← [ C ] ← [ D ] ← (new person joins here)\n   ↑\n (cashier serves whoever is here next)\n","text",[42,43,39],"code",{"__ignoreMap":44},"",[11,46,47],{},"Two rules govern this line:",[49,50,51,57],"ul",{},[52,53,54],"li",{},[15,55,56],{},"New people join at the rear.",[52,58,59,62,63,66],{},[15,60,61],{},"The cashier always serves whoever is at the front.","\nThat's it. That's a queue. And the rule it follows has a famous three-letter name: ",[15,64,65],{},"FIFO — First In, First Out."," The first person in line is the first person out.",[11,68,69,70,73],{},"Compare this to a ",[15,71,72],{},"stack",", which is LIFO (Last In, First Out) — like a stack of plates where you only take the top one. Same family of \"linear\" structures, different access rule.",[27,75,77],{"id":76},"_2-where-queues-live-in-java","2. Where queues live in Java",[11,79,80,81,84,85,88],{},"Before we build one, let's see where ",[42,82,83],{},"Queue"," sits in Java's official ",[15,86,87],{},"Collections Framework",":",[35,90,93],{"className":91,"code":92,"language":40},[38],"                  Iterable\n                     │\n                 Collection\n                ┌────┼─────┐\n              List   Queue   Set\n               │      │       │\n        ArrayList   PriorityQueue   HashSet\n        LinkedList     Deque       LinkedHashSet\n        Vector       ArrayDeque    TreeSet\n        Stack\n",[42,94,92],{"__ignoreMap":44},[11,96,97],{},"A few takeaways:",[49,99,100,117,137],{},[52,101,102,104,105,108,109,112,113,116],{},[42,103,83],{}," is a sibling of ",[42,106,107],{},"List"," and ",[42,110,111],{},"Set"," — they're all ",[42,114,115],{},"Collection","s.",[52,118,119,121,122,125,126,129,130,133,134,22],{},[42,120,83],{}," is an ",[15,123,124],{},"interface",", not a concrete class. You don't ",[42,127,128],{},"new Queue()",". You use an implementation like ",[42,131,132],{},"LinkedList"," or ",[42,135,136],{},"PriorityQueue",[52,138,139,142],{},[42,140,141],{},"Deque"," (double-ended queue) is a more flexible cousin that allows add\u002Fremove at both ends. We won't focus on it here.",[27,144,146],{"id":145},"_3-the-two-operations-that-define-a-queue","3. The two operations that define a queue",[11,148,149],{},"You only really need two:",[151,152,153,169],"table",{},[154,155,156],"thead",{},[157,158,159,163,166],"tr",{},[160,161,162],"th",{},"Operation",[160,164,165],{},"What it does",[160,167,168],{},"Where it happens",[170,171,172,193],"tbody",{},[157,173,174,180,187],{},[175,176,177],"td",{},[42,178,179],{},"enqueue(x)",[175,181,182,183,186],{},"Add ",[42,184,185],{},"x"," to the queue",[175,188,189,190],{},"At the ",[15,191,192],{},"rear",[157,194,195,200,203],{},[175,196,197],{},[42,198,199],{},"dequeue()",[175,201,202],{},"Remove and return the next element",[175,204,205,206],{},"From the ",[15,207,208],{},"front",[11,210,211,212,215,216,219,220,223,224,108,227,230],{},"You'll often also see helpers like ",[42,213,214],{},"peek()"," (look at the front without removing), ",[42,217,218],{},"size()",", and ",[42,221,222],{},"isEmpty()",". But ",[42,225,226],{},"enqueue",[42,228,229],{},"dequeue"," are the heart of it.",[232,233,235],"h3",{"id":234},"try-it-yourself","Try it yourself",[11,237,238,239,242,243,246],{},"I built a tiny visualizer — type a value, hit ",[42,240,241],{},"ENQUEUE",", watch it appear at the rear. Hit ",[42,244,245],{},"DEQUEUE"," to pull from the front. The borders highlight which node is the front (red) and which is the rear (blue).",[248,249],"custom-html",{"code":250},"\u003C!DOCTYPE html>\n\u003Chtml lang=\"en\">\n\u003Chead>\n\u003Cmeta charset=\"UTF-8\" \u002F>\n\u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \u002F>\n\u003Ctitle>Queue Visualizer\u003C\u002Ftitle>\n\u003Cstyle>\n  :root {\n    --paper: #f6f1e8;\n    --ink: #2b2a26;\n    --muted: #7a7468;\n    --line: #1a1916;\n    --front: #c9412c;\n    --rear:  #2563a8;\n    --accent: #d9a441;\n    --shadow: 4px 4px 0 var(--line);\n  }\n  * { box-sizing: border-box; }\n  html, body {\n    margin: 0; padding: 0;\n    font-family: \"Georgia\", \"Cambria\", serif;\n    background: var(--paper);\n    color: var(--ink);\n  }\n  body {\n    background-image:\n      radial-gradient(circle at 20% 10%, rgba(0,0,0,0.03) 0, transparent 60%),\n      radial-gradient(circle at 80% 90%, rgba(0,0,0,0.03) 0, transparent 60%);\n    padding: 32px 20px;\n  }\n  .wrap {\n    max-width: 760px; margin: 0 auto;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    padding: 28px 28px 24px;\n    box-shadow: var(--shadow);\n    position: relative;\n  }\n  .wrap::before {\n    content: \"FIFO\";\n    position: absolute; top: -14px; left: 22px;\n    background: var(--accent);\n    color: var(--line);\n    font-family: \"Courier New\", monospace;\n    font-weight: 700;\n    font-size: 12px;\n    letter-spacing: 2px;\n    padding: 3px 10px;\n    border: 2px solid var(--line);\n  }\n  h1 {\n    font-family: \"Georgia\", serif;\n    font-weight: 700;\n    font-size: 26px;\n    margin: 4px 0 4px;\n    letter-spacing: -0.5px;\n  }\n  .sub {\n    font-style: italic;\n    color: var(--muted);\n    margin: 0 0 20px;\n    font-size: 14px;\n  }\n  .controls {\n    display: flex; flex-wrap: wrap; gap: 8px;\n    align-items: center;\n    padding: 14px;\n    background: #f1ead9;\n    border: 1.5px dashed var(--line);\n    margin-bottom: 22px;\n  }\n  .controls input[type=\"text\"] {\n    flex: 1; min-width: 120px;\n    padding: 8px 10px;\n    font-family: \"Courier New\", monospace;\n    font-size: 14px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    outline: none;\n  }\n  .controls input[type=\"text\"]:focus {\n    background: #fff;\n    box-shadow: 2px 2px 0 var(--line);\n    transform: translate(-1px, -1px);\n  }\n  button {\n    font-family: \"Courier New\", monospace;\n    font-size: 13px;\n    font-weight: 700;\n    letter-spacing: 1px;\n    padding: 8px 14px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    color: var(--ink);\n    cursor: pointer;\n    transition: transform 0.08s ease, box-shadow 0.08s ease;\n  }\n  button:hover { transform: translate(-1px, -1px); box-shadow: 2px 2px 0 var(--line); }\n  button:active { transform: translate(1px, 1px); box-shadow: none; }\n  .btn-enq { background: #d9eedd; }\n  .btn-deq { background: #f4d3c9; }\n  .btn-clr { background: #fffdf7; }\n  .stage {\n    position: relative;\n    min-height: 180px;\n    padding: 28px 12px 12px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    overflow: hidden;\n  }\n  .labels {\n    position: absolute; top: 6px; left: 12px; right: 12px;\n    display: flex; justify-content: space-between;\n    font-family: \"Courier New\", monospace;\n    font-size: 11px;\n    letter-spacing: 1.5px;\n    color: var(--muted);\n  }\n  .labels .front-l { color: var(--front); }\n  .labels .rear-l  { color: var(--rear);  }\n  .queue {\n    display: flex; align-items: center; justify-content: flex-start;\n    gap: 6px;\n    \u002F* FIX: Increased bottom padding so text doesn't get clipped by the scroll area *\u002F\n    padding: 18px 6px 32px; \n    min-height: 110px; \u002F* adjusted to account for new padding *\u002F\n    overflow-x: auto;\n  }\n  .queue::-webkit-scrollbar { height: 6px; }\n  .queue::-webkit-scrollbar-thumb { background: var(--muted); }\n  .node {\n    flex-shrink: 0;\n    min-width: 60px;\n    height: 56px;\n    display: flex; align-items: center; justify-content: center;\n    font-family: \"Courier New\", monospace;\n    font-weight: 700;\n    font-size: 16px;\n    background: #fffdf7;\n    border: 2px solid var(--line);\n    box-shadow: 3px 3px 0 var(--line);\n    position: relative;\n    animation: slideIn 0.35s cubic-bezier(.2,.9,.3,1.2);\n  }\n  .node.first { border-color: var(--front); }\n  .node.last  { border-color: var(--rear);  }\n  .node.first::after,\n  .node.last::after {\n    position: absolute;\n    \u002F* FIX: Pushed down slightly & added nowrap to prevent overlapping *\u002F\n    bottom: -28px; \n    left: 50%; transform: translateX(-50%);\n    font-family: \"Courier New\", monospace;\n    font-size: 10px;\n    letter-spacing: 1px;\n    white-space: nowrap; \n  }\n  .node.first::after { content: \"FRONT ↑\"; color: var(--front); }\n  .node.last::after  { content: \"REAR ↑\";  color: var(--rear);  }\n  .node.first.last::after { content: \"FRONT & REAR ↑\"; color: var(--ink); }\n  .node.leaving {\n    animation: slideOut 0.3s ease forwards;\n  }\n  @keyframes slideIn {\n    0%   { transform: translateX(30px) scale(0.7); opacity: 0; }\n    100% { transform: translateX(0) scale(1); opacity: 1; }\n  }\n  @keyframes slideOut {\n    0%   { transform: translateX(0) scale(1); opacity: 1; }\n    100% { transform: translateX(-50px) scale(0.7); opacity: 0; }\n  }\n  .empty {\n    color: var(--muted);\n    font-style: italic;\n    font-family: \"Georgia\", serif;\n    text-align: center;\n    width: 100%;\n    padding: 24px 0;\n  }\n  .log {\n    margin-top: 18px;\n    font-family: \"Courier New\", monospace;\n    font-size: 12px;\n    background: var(--line);\n    color: #f3e9c8;\n    padding: 12px 14px;\n    height: 110px;\n    overflow-y: auto;\n    border: 2px solid var(--line);\n  }\n  .log div { margin-bottom: 2px; }\n  .log .ok  { color: #9be4a3; }\n  .log .err { color: #f49d8e; }\n  .log .info { color: #f3e9c8; }\n  .stats {\n    margin-top: 12px;\n    display: flex; gap: 18px;\n    font-family: \"Courier New\", monospace;\n    font-size: 13px;\n    color: var(--muted);\n  }\n  .stats b { color: var(--ink); }\n\u003C\u002Fstyle>\n\u003C\u002Fhead>\n\u003Cbody>\n\u003Cdiv class=\"wrap\">\n  \u003Ch1>Queue Visualizer\u003C\u002Fh1>\n  \u003Cp class=\"sub\">Watch elements line up at the rear and leave from the front.\u003C\u002Fp>\n \n  \u003Cdiv class=\"controls\">\n    \u003Cinput id=\"val\" type=\"text\" placeholder=\"Enter a value (e.g. Tom)\" maxlength=\"10\" \u002F>\n    \u003Cbutton class=\"btn-enq\" onclick=\"enqueue()\">ENQUEUE\u003C\u002Fbutton>\n    \u003Cbutton class=\"btn-deq\" onclick=\"dequeue()\">DEQUEUE\u003C\u002Fbutton>\n    \u003Cbutton class=\"btn-clr\" onclick=\"clearQueue()\">CLEAR\u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"stage\">\n    \u003Cdiv class=\"labels\">\n      \u003Cspan class=\"front-l\">← front (remove here)\u003C\u002Fspan>\n      \u003Cspan class=\"rear-l\">rear (add here) →\u003C\u002Fspan>\n    \u003C\u002Fdiv>\n    \u003Cdiv id=\"queue\" class=\"queue\">\n      \u003Cdiv class=\"empty\">— queue is empty —\u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"stats\">\n    \u003Cspan>size: \u003Cb id=\"size\">0\u003C\u002Fb>\u003C\u002Fspan>\n    \u003Cspan>front: \u003Cb id=\"frontEl\">∅\u003C\u002Fb>\u003C\u002Fspan>\n    \u003Cspan>rear: \u003Cb id=\"rearEl\">∅\u003C\u002Fb>\u003C\u002Fspan>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"log\" id=\"log\">\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n \n\u003Cscript>\n  const queue = [];\n  const queueEl = document.getElementById(\"queue\");\n  const logEl = document.getElementById(\"log\");\n  const valEl = document.getElementById(\"val\");\n  let counter = 0;\n \n  function log(msg, type = \"info\") {\n    const line = document.createElement(\"div\");\n    line.className = type;\n    line.textContent = \"> \" + msg;\n    logEl.appendChild(line);\n    logEl.scrollTop = logEl.scrollHeight;\n  }\n \n  function render() {\n    queueEl.innerHTML = \"\";\n    if (queue.length === 0) {\n      const empty = document.createElement(\"div\");\n      empty.className = \"empty\";\n      empty.textContent = \"— queue is empty —\";\n      queueEl.appendChild(empty);\n    } else {\n      queue.forEach((item, i) => {\n        const node = document.createElement(\"div\");\n        node.className = \"node\";\n        if (i === 0) node.classList.add(\"first\");\n        if (i === queue.length - 1) node.classList.add(\"last\");\n        node.textContent = item.value;\n        node.dataset.id = item.id;\n        queueEl.appendChild(node);\n      });\n    }\n    document.getElementById(\"size\").textContent = queue.length;\n    document.getElementById(\"frontEl\").textContent = queue[0]?.value ?? \"∅\";\n    document.getElementById(\"rearEl\").textContent = queue[queue.length - 1]?.value ?? \"∅\";\n  }\n \n  function enqueue() {\n    const v = valEl.value.trim();\n    if (!v) {\n      log(\"enqueue failed — value is empty\", \"err\");\n      return;\n    }\n    queue.push({ value: v, id: counter++ });\n    log(\"enqueue(\\\"\" + v + \"\\\")  →  added at rear\", \"ok\");\n    valEl.value = \"\";\n    valEl.focus();\n    render();\n  }\n \n  function dequeue() {\n    if (queue.length === 0) {\n      log(\"dequeue failed — queue is empty\", \"err\");\n      return;\n    }\n    const removed = queue[0];\n    const firstNode = queueEl.querySelector(\".node.first\");\n    if (firstNode) {\n      firstNode.classList.add(\"leaving\");\n      setTimeout(() => {\n        queue.shift();\n        log(\"dequeue()  →  removed \\\"\" + removed.value + \"\\\" from front\", \"ok\");\n        render();\n      }, 280);\n    } else {\n      queue.shift();\n      render();\n    }\n  }\n \n  function clearQueue() {\n    if (queue.length === 0) { log(\"queue already empty\", \"info\"); return; }\n    queue.length = 0;\n    log(\"cleared the queue\", \"info\");\n    render();\n  }\n \n  valEl.addEventListener(\"keydown\", (e) => {\n    if (e.key === \"Enter\") enqueue();\n  });\n \n  \u002F\u002F Seed with a small demo\n  [\"Tom\", \"Susan\", \"Kim\"].forEach(v => queue.push({ value: v, id: counter++ }));\n  render();\n  log(\"queue initialized with 3 elements\", \"info\");\n\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>",[27,252,254],{"id":253},"_4-implementing-a-queue-why-a-linked-list-wins","4. Implementing a queue: why a linked list wins",[11,256,257,258,261,262,264],{},"Here's a subtle but important question: should I use an ",[42,259,260],{},"ArrayList"," or a ",[42,263,132],{}," under the hood?",[11,266,267],{},"Let's think about what each operation costs.",[11,269,270,273,274],{},[15,271,272],{},"With an"," ",[15,275,276,88],{},[42,277,260],{},[49,279,280,285,297,302],{},[52,281,282,284],{},[42,283,226],{}," (add at end) → cheap, just appends. ✅",[52,286,287,289,290,273,293],{},[42,288,229],{}," (remove from index 0) → ⚠️ expensive! Every other element has to shift left by one. That's an O(n) hit on every removal.\n",[15,291,292],{},"With a",[15,294,295,88],{},[42,296,132],{},[52,298,299,301],{},[42,300,226],{}," (add at tail) → O(1). ✅",[52,303,304,306],{},[42,305,229],{}," (remove from head) → O(1). ✅\nBoth queue operations are constant-time with a linked list. That's why the textbook recommends a linked list as the backing structure for a queue.",[35,308,311],{"className":309,"code":310,"language":40},[38],"   Queue conceptually          Queue implemented as a LinkedList\n \n   ┌───┬───┬───┐                ┌───┐   ┌───┐   ┌───┐\n   │ A │ B │ C │                │ A │ → │ B │ → │ C │\n   └───┴───┴───┘                └───┘   └───┘   └───┘\n    front     rear                first           last\n                                  (dequeue        (enqueue\n                                   from here)      to here)\n",[42,312,310],{"__ignoreMap":44},[27,314,316,317,320,321],{"id":315},"_5-two-ways-to-wire-a-genericqueue-to-a-linkedlist","5. Two ways to wire a ",[42,318,319],{},"GenericQueue"," to a ",[42,322,132],{},[11,324,325],{},"Once you've decided to use a linked list, you still have a design choice. Java's textbook author Y. Daniel Liang lays out two paths.",[232,327,329,330],{"id":328},"option-a-inheritance-genericqueue-extends-linkedlist","Option A: Inheritance — ",[42,331,332],{},"GenericQueue extends LinkedList",[11,334,335,336,339],{},"Your queue ",[15,337,338],{},"is-a"," linked list, and inherits all of its methods.",[49,341,342,345],{},[52,343,344],{},"✅ Easy to write.",[52,346,347,348,273,352,354,355,358,359,362],{},"❌ But… your queue now exposes ",[349,350,351],"em",{},"every",[42,353,132],{}," method (like ",[42,356,357],{},"add(int index, E e)",", ",[42,360,361],{},"get(i)",", etc.). That breaks the queue's contract — users can sneakily insert in the middle, peek at index 5, all sorts of things a real queue shouldn't allow.",[232,364,366,367,273,369,273,372],{"id":365},"option-b-composition-genericqueue-has-a-linkedlist","Option B: Composition — ",[42,368,319],{},[349,370,371],{},"has-a",[42,373,132],{},[11,375,335,376,379,380,358,382,358,384,22],{},[15,377,378],{},"owns"," a private linked list and only exposes ",[42,381,226],{},[42,383,229],{},[42,385,386],{},"getSize",[49,388,389,392,398],{},[52,390,391],{},"✅ Encapsulates the implementation. The user can only do queue things.",[52,393,394,395,397],{},"✅ You could swap the internal ",[42,396,132],{}," for something else later without breaking callers.",[52,399,400],{},"This is the preferred design.",[35,402,405],{"className":403,"code":404,"language":40},[38],"   (a) Inheritance                    (b) Composition\n \n   LinkedList ◁──── GenericQueue      GenericQueue ◆──── LinkedList\n                                       (holds one privately)\n",[42,406,404],{"__ignoreMap":44},[408,409,410],"blockquote",{},[11,411,412,415,416,419],{},[15,413,414],{},"Rule of thumb:"," Prefer composition over inheritance unless your subclass is genuinely a more specific ",[349,417,418],{},"kind"," of the parent. A queue isn't a \"kind of linked list\" — it's a different abstraction that happens to use one internally.",[27,421,423,424,427],{"id":422},"_6-genericqueuee-the-code","6. ",[42,425,426],{},"GenericQueue\u003CE>"," — the code",[11,429,430],{},"Here's the textbook implementation using composition. It's short enough to memorize:",[35,432,436],{"className":433,"code":434,"language":435,"meta":44,"style":44},"language-java shiki shiki-themes github-light github-dark","public class GenericQueue\u003CE> {\n    private java.util.LinkedList\u003CE> list = new java.util.LinkedList\u003C>();\n \n    public void enqueue(E e) {\n        list.addLast(e);          \u002F\u002F add at rear\n    }\n \n    public E dequeue() {\n        return list.removeFirst(); \u002F\u002F remove from front\n    }\n \n    public int getSize() {\n        return list.size();\n    }\n \n    @Override\n    public String toString() {\n        return \"Queue: \" + list.toString();\n    }\n}\n","java",[42,437,438,464,487,493,515,531,537,542,555,573,578,583,596,609,614,619,628,641,659,664],{"__ignoreMap":44},[439,440,443,447,450,454,458,461],"span",{"class":441,"line":442},"line",1,[439,444,446],{"class":445},"szBVR","public",[439,448,449],{"class":445}," class",[439,451,453],{"class":452},"sScJk"," GenericQueue",[439,455,457],{"class":456},"sVt8B","\u003C",[439,459,460],{"class":445},"E",[439,462,463],{"class":456},"> {\n",[439,465,467,470,473,475,478,481,484],{"class":441,"line":466},2,[439,468,469],{"class":445},"    private",[439,471,472],{"class":456}," java.util.LinkedList\u003C",[439,474,460],{"class":445},[439,476,477],{"class":456},"> list ",[439,479,480],{"class":445},"=",[439,482,483],{"class":445}," new",[439,485,486],{"class":456}," java.util.LinkedList\u003C>();\n",[439,488,490],{"class":441,"line":489},3,[439,491,492],{"class":456}," \n",[439,494,496,499,502,505,508,512],{"class":441,"line":495},4,[439,497,498],{"class":445},"    public",[439,500,501],{"class":445}," void",[439,503,504],{"class":452}," enqueue",[439,506,507],{"class":456},"(E ",[439,509,511],{"class":510},"s4XuR","e",[439,513,514],{"class":456},") {\n",[439,516,518,521,524,527],{"class":441,"line":517},5,[439,519,520],{"class":456},"        list.",[439,522,523],{"class":452},"addLast",[439,525,526],{"class":456},"(e);          ",[439,528,530],{"class":529},"sJ8bj","\u002F\u002F add at rear\n",[439,532,534],{"class":441,"line":533},6,[439,535,536],{"class":456},"    }\n",[439,538,540],{"class":441,"line":539},7,[439,541,492],{"class":456},[439,543,545,547,550,552],{"class":441,"line":544},8,[439,546,498],{"class":445},[439,548,549],{"class":456}," E ",[439,551,229],{"class":452},[439,553,554],{"class":456},"() {\n",[439,556,558,561,564,567,570],{"class":441,"line":557},9,[439,559,560],{"class":445},"        return",[439,562,563],{"class":456}," list.",[439,565,566],{"class":452},"removeFirst",[439,568,569],{"class":456},"(); ",[439,571,572],{"class":529},"\u002F\u002F remove from front\n",[439,574,576],{"class":441,"line":575},10,[439,577,536],{"class":456},[439,579,581],{"class":441,"line":580},11,[439,582,492],{"class":456},[439,584,586,588,591,594],{"class":441,"line":585},12,[439,587,498],{"class":445},[439,589,590],{"class":445}," int",[439,592,593],{"class":452}," getSize",[439,595,554],{"class":456},[439,597,599,601,603,606],{"class":441,"line":598},13,[439,600,560],{"class":445},[439,602,563],{"class":456},[439,604,605],{"class":452},"size",[439,607,608],{"class":456},"();\n",[439,610,612],{"class":441,"line":611},14,[439,613,536],{"class":456},[439,615,617],{"class":441,"line":616},15,[439,618,492],{"class":456},[439,620,622,625],{"class":441,"line":621},16,[439,623,624],{"class":456},"    @",[439,626,627],{"class":445},"Override\n",[439,629,631,633,636,639],{"class":441,"line":630},17,[439,632,498],{"class":445},[439,634,635],{"class":456}," String ",[439,637,638],{"class":452},"toString",[439,640,554],{"class":456},[439,642,644,646,650,653,655,657],{"class":441,"line":643},18,[439,645,560],{"class":445},[439,647,649],{"class":648},"sZZnC"," \"Queue: \"",[439,651,652],{"class":445}," +",[439,654,563],{"class":456},[439,656,638],{"class":452},[439,658,608],{"class":456},[439,660,662],{"class":441,"line":661},19,[439,663,536],{"class":456},[439,665,667],{"class":441,"line":666},20,[439,668,669],{"class":456},"}\n",[11,671,672],{},"A few things worth noticing:",[49,674,675,696,706],{},[52,676,677,680,681,684,685,358,688,691,692,695],{},[42,678,679],{},"\u003CE>"," is a ",[15,682,683],{},"generic type parameter",". It lets you build ",[42,686,687],{},"GenericQueue\u003CString>",[42,689,690],{},"GenericQueue\u003CInteger>",", or ",[42,693,694],{},"GenericQueue\u003CMyOwnClass>"," from the same definition.",[52,697,698,108,700,702,703,705],{},[42,699,523],{},[42,701,566],{}," are methods Java's ",[42,704,132],{}," already provides. We're just renaming them to the queue vocabulary.",[52,707,708,709,712,713,716],{},"The internal ",[42,710,711],{},"list"," is ",[42,714,715],{},"private"," — outside code can't reach in and break invariants.",[232,718,720],{"id":719},"testing-it","Testing it",[35,722,724],{"className":433,"code":723,"language":435,"meta":44,"style":44},"GenericQueue\u003CString> queue = new GenericQueue\u003C>();\n \nqueue.enqueue(\"Tom\");          \u002F\u002F Queue: [Tom]\nqueue.enqueue(\"Susan\");        \u002F\u002F Queue: [Tom, Susan]\nqueue.enqueue(\"Kim\");\nqueue.enqueue(\"Michael\");      \u002F\u002F Queue: [Tom, Susan, Kim, Michael]\n \nSystem.out.println(queue.dequeue()); \u002F\u002F Tom\nSystem.out.println(queue.dequeue()); \u002F\u002F Susan\nSystem.out.println(queue);           \u002F\u002F Queue: [Kim, Michael]\n",[42,725,726,744,748,767,784,798,815,819,838,853],{"__ignoreMap":44},[439,727,728,731,734,737,739,741],{"class":441,"line":442},[439,729,730],{"class":456},"GenericQueue\u003C",[439,732,733],{"class":445},"String",[439,735,736],{"class":456},"> queue ",[439,738,480],{"class":445},[439,740,483],{"class":445},[439,742,743],{"class":456}," GenericQueue\u003C>();\n",[439,745,746],{"class":441,"line":466},[439,747,492],{"class":456},[439,749,750,753,755,758,761,764],{"class":441,"line":489},[439,751,752],{"class":456},"queue.",[439,754,226],{"class":452},[439,756,757],{"class":456},"(",[439,759,760],{"class":648},"\"Tom\"",[439,762,763],{"class":456},");          ",[439,765,766],{"class":529},"\u002F\u002F Queue: [Tom]\n",[439,768,769,771,773,775,778,781],{"class":441,"line":495},[439,770,752],{"class":456},[439,772,226],{"class":452},[439,774,757],{"class":456},[439,776,777],{"class":648},"\"Susan\"",[439,779,780],{"class":456},");        ",[439,782,783],{"class":529},"\u002F\u002F Queue: [Tom, Susan]\n",[439,785,786,788,790,792,795],{"class":441,"line":517},[439,787,752],{"class":456},[439,789,226],{"class":452},[439,791,757],{"class":456},[439,793,794],{"class":648},"\"Kim\"",[439,796,797],{"class":456},");\n",[439,799,800,802,804,806,809,812],{"class":441,"line":533},[439,801,752],{"class":456},[439,803,226],{"class":452},[439,805,757],{"class":456},[439,807,808],{"class":648},"\"Michael\"",[439,810,811],{"class":456},");      ",[439,813,814],{"class":529},"\u002F\u002F Queue: [Tom, Susan, Kim, Michael]\n",[439,816,817],{"class":441,"line":539},[439,818,492],{"class":456},[439,820,821,824,827,830,832,835],{"class":441,"line":544},[439,822,823],{"class":456},"System.out.",[439,825,826],{"class":452},"println",[439,828,829],{"class":456},"(queue.",[439,831,229],{"class":452},[439,833,834],{"class":456},"()); ",[439,836,837],{"class":529},"\u002F\u002F Tom\n",[439,839,840,842,844,846,848,850],{"class":441,"line":557},[439,841,823],{"class":456},[439,843,826],{"class":452},[439,845,829],{"class":456},[439,847,229],{"class":452},[439,849,834],{"class":456},[439,851,852],{"class":529},"\u002F\u002F Susan\n",[439,854,855,857,859,862],{"class":441,"line":575},[439,856,823],{"class":456},[439,858,826],{"class":452},[439,860,861],{"class":456},"(queue);           ",[439,863,864],{"class":529},"\u002F\u002F Queue: [Kim, Michael]\n",[11,866,867,868,871,872,875],{},"Notice how Tom — the ",[15,869,870],{},"first one in"," — is also the ",[15,873,874],{},"first one out",". FIFO in action.",[27,877,879],{"id":878},"_7-priority-queues-when-fifo-isnt-enough","7. Priority Queues — when FIFO isn't enough",[11,881,882],{},"Now imagine an emergency room.",[11,884,885],{},"A patient with a stab wound arrives at 10:00 AM. A patient with a sprained ankle arrives at 10:05 AM. Should the ankle be treated first because they arrived first? Of course not.",[11,887,888,889,892],{},"That's the limitation of a plain queue: it doesn't care ",[15,890,891],{},"how important"," an element is. In real life, sometimes you need to jump the line.",[408,894,895],{},[11,896,897,900,901,904],{},[15,898,899],{},"Priority Queue:"," A queue where each element has a ",[349,902,903],{},"priority",", and the highest-priority element comes out first — regardless of insertion order.",[11,906,907,908,911,912,133,915,918],{},"Some people call this ",[15,909,910],{},"\"largest-in, first-out\""," behavior, though as you'll see, \"largest\" can mean either ",[349,913,914],{},"biggest number",[349,916,917],{},"smallest number"," depending on how you set it up.",[232,920,922],{"id":921},"visualizing-it","Visualizing it",[11,924,925,926,929,930,933],{},"Here's the classic textbook picture: elements are dumped into a container with priorities, and removal always pulls out the highest-priority one. With ",[42,927,928],{},"8, 3, 18, 15, 13"," in the bowl (higher number = higher priority), ",[42,931,932],{},"18"," leaves first.",[248,935],{"code":936},"\u003C!DOCTYPE html>\n\u003Chtml lang=\"en\">\n\u003Chead>\n\u003Cmeta charset=\"UTF-8\" \u002F>\n\u003Cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" \u002F>\n\u003Ctitle>Priority Queue Visualizer\u003C\u002Ftitle>\n\u003Cstyle>\n  :root {\n    --paper: #f6f1e8;\n    --ink: #2b2a26;\n    --muted: #7a7468;\n    --line: #1a1916;\n    --hot: #c9412c;\n    --cold: #5a8fbf;\n    --accent: #d9a441;\n    --shadow: 4px 4px 0 var(--line);\n  }\n  * { box-sizing: border-box; }\n  html, body {\n    margin: 0; padding: 0;\n    font-family: \"Georgia\", \"Cambria\", serif;\n    background: var(--paper);\n    color: var(--ink);\n  }\n  body {\n    background-image:\n      radial-gradient(circle at 20% 10%, rgba(0,0,0,0.03) 0, transparent 60%),\n      radial-gradient(circle at 80% 90%, rgba(0,0,0,0.03) 0, transparent 60%);\n    padding: 32px 20px;\n  }\n  .wrap {\n    max-width: 760px; margin: 0 auto;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    padding: 28px 28px 24px;\n    box-shadow: var(--shadow);\n    position: relative;\n  }\n  .wrap::before {\n    content: \"PRIORITY\";\n    position: absolute; top: -14px; left: 22px;\n    background: var(--accent);\n    color: var(--line);\n    font-family: \"Courier New\", monospace;\n    font-weight: 700;\n    font-size: 12px;\n    letter-spacing: 2px;\n    padding: 3px 10px;\n    border: 2px solid var(--line);\n  }\n  h1 {\n    font-family: \"Georgia\", serif;\n    font-weight: 700;\n    font-size: 26px;\n    margin: 4px 0 4px;\n    letter-spacing: -0.5px;\n  }\n  .sub {\n    font-style: italic;\n    color: var(--muted);\n    margin: 0 0 16px;\n    font-size: 14px;\n  }\n  .mode-toggle {\n    display: inline-flex;\n    border: 2px solid var(--line);\n    margin-bottom: 18px;\n    font-family: \"Courier New\", monospace;\n    font-size: 12px;\n    font-weight: 700;\n  }\n  .mode-toggle button {\n    background: #fffdf7;\n    border: none;\n    padding: 6px 14px;\n    cursor: pointer;\n    color: var(--muted);\n    letter-spacing: 1px;\n  }\n  .mode-toggle button.active {\n    background: var(--ink);\n    color: var(--accent);\n  }\n  .controls {\n    display: flex; flex-wrap: wrap; gap: 8px;\n    align-items: center;\n    padding: 14px;\n    background: #f1ead9;\n    border: 1.5px dashed var(--line);\n    margin-bottom: 22px;\n  }\n  .controls input {\n    padding: 8px 10px;\n    font-family: \"Courier New\", monospace;\n    font-size: 14px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    outline: none;\n  }\n  .controls input:focus {\n    background: #fff;\n    box-shadow: 2px 2px 0 var(--line);\n    transform: translate(-1px, -1px);\n  }\n  .controls input.val   { flex: 2; min-width: 100px; }\n  .controls input.prio  { width: 80px; }\n  button {\n    font-family: \"Courier New\", monospace;\n    font-size: 13px;\n    font-weight: 700;\n    letter-spacing: 1px;\n    padding: 8px 14px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n    color: var(--ink);\n    cursor: pointer;\n    transition: transform 0.08s ease, box-shadow 0.08s ease;\n  }\n  button:hover { transform: translate(-1px, -1px); box-shadow: 2px 2px 0 var(--line); }\n  button:active { transform: translate(1px, 1px); box-shadow: none; }\n  .btn-add  { background: #d9eedd; }\n  .btn-poll { background: #f4d3c9; }\n  .btn-clr  { background: #fffdf7; }\n  .stage {\n    position: relative;\n    min-height: 200px;\n    padding: 28px 12px 36px;\n    border: 2px solid var(--line);\n    background: #fffdf7;\n  }\n  .stage-label {\n    position: absolute; top: 6px; left: 12px;\n    font-family: \"Courier New\", monospace;\n    font-size: 11px;\n    letter-spacing: 1.5px;\n    color: var(--muted);\n  }\n  .stage-label b { color: var(--hot); }\n  .queue {\n    display: flex; flex-wrap: wrap;\n    gap: 10px;\n    padding: 18px 6px 6px;\n    min-height: 120px;\n    align-items: center;\n    justify-content: center;\n  }\n  .node {\n    min-width: 90px;\n    padding: 10px 8px 6px;\n    display: flex; flex-direction: column; align-items: center;\n    font-family: \"Courier New\", monospace;\n    background: #fffdf7;\n    border: 2px solid var(--line);\n    box-shadow: 3px 3px 0 var(--line);\n    position: relative;\n    transition: transform 0.4s cubic-bezier(.2,.9,.3,1.2);\n    animation: pop 0.35s cubic-bezier(.2,.9,.3,1.2);\n  }\n  .node .value {\n    font-weight: 700;\n    font-size: 15px;\n  }\n  .node .prio {\n    font-size: 11px;\n    color: var(--muted);\n    margin-top: 4px;\n    letter-spacing: 1px;\n  }\n  .node.next {\n    border-color: var(--hot);\n    background: #fff4ef;\n  }\n  .node.next::after {\n    content: \"↑ NEXT OUT\";\n    position: absolute;\n    bottom: -22px; left: 50%; transform: translateX(-50%);\n    font-size: 10px;\n    color: var(--hot);\n    letter-spacing: 1px;\n    white-space: nowrap;\n  }\n  .node.leaving {\n    animation: fly 0.4s ease forwards;\n  }\n  @keyframes pop {\n    0%   { transform: scale(0.5); opacity: 0; }\n    100% { transform: scale(1); opacity: 1; }\n  }\n  @keyframes fly {\n    0%   { transform: translateY(0) scale(1); opacity: 1; }\n    100% { transform: translateY(-40px) scale(0.6); opacity: 0; }\n  }\n  .empty {\n    color: var(--muted);\n    font-style: italic;\n    font-family: \"Georgia\", serif;\n    text-align: center;\n    width: 100%;\n    padding: 24px 0;\n  }\n  .log {\n    margin-top: 18px;\n    font-family: \"Courier New\", monospace;\n    font-size: 12px;\n    background: var(--line);\n    color: #f3e9c8;\n    padding: 12px 14px;\n    height: 110px;\n    overflow-y: auto;\n    border: 2px solid var(--line);\n  }\n  .log div { margin-bottom: 2px; }\n  .log .ok  { color: #9be4a3; }\n  .log .err { color: #f49d8e; }\n  .log .info { color: #f3e9c8; }\n\u003C\u002Fstyle>\n\u003C\u002Fhead>\n\u003Cbody>\n\u003Cdiv class=\"wrap\">\n  \u003Ch1>Priority Queue Visualizer\u003C\u002Fh1>\n  \u003Cp class=\"sub\">Each item has a priority. The one with the highest priority leaves first — order in doesn't matter.\u003C\u002Fp>\n \n  \u003Cdiv class=\"mode-toggle\">\n    \u003Cbutton id=\"hiBtn\" class=\"active\" onclick=\"setMode('high')\">HIGHER = HIGHER PRIORITY\u003C\u002Fbutton>\n    \u003Cbutton id=\"loBtn\" onclick=\"setMode('low')\">LOWER = HIGHER PRIORITY\u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"controls\">\n    \u003Cinput class=\"val\"  id=\"val\"  type=\"text\"   placeholder=\"value (e.g. patient name)\" maxlength=\"14\" \u002F>\n    \u003Cinput class=\"prio\" id=\"prio\" type=\"number\" placeholder=\"priority\" \u002F>\n    \u003Cbutton class=\"btn-add\"  onclick=\"addItem()\">OFFER\u003C\u002Fbutton>\n    \u003Cbutton class=\"btn-poll\" onclick=\"pollItem()\">POLL\u003C\u002Fbutton>\n    \u003Cbutton class=\"btn-clr\"  onclick=\"clearQ()\">CLEAR\u003C\u002Fbutton>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"stage\">\n    \u003Cdiv class=\"stage-label\">order shown by priority — \u003Cb>highlighted = poll() returns this next\u003C\u002Fb>\u003C\u002Fdiv>\n    \u003Cdiv id=\"queue\" class=\"queue\">\n      \u003Cdiv class=\"empty\">— priority queue is empty —\u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n \n  \u003Cdiv class=\"log\" id=\"log\">\u003C\u002Fdiv>\n\u003C\u002Fdiv>\n \n\u003Cscript>\n  let queue = [];\n  let mode = \"high\"; \u002F\u002F \"high\" = larger number wins, \"low\" = smaller number wins\n  let counter = 0;\n  const queueEl = document.getElementById(\"queue\");\n  const logEl = document.getElementById(\"log\");\n  const valEl = document.getElementById(\"val\");\n  const prioEl = document.getElementById(\"prio\");\n \n  function log(msg, type = \"info\") {\n    const line = document.createElement(\"div\");\n    line.className = type;\n    line.textContent = \"> \" + msg;\n    logEl.appendChild(line);\n    logEl.scrollTop = logEl.scrollHeight;\n  }\n \n  function compare(a, b) {\n    return mode === \"high\" ? b.priority - a.priority : a.priority - b.priority;\n  }\n \n  function sortedView() {\n    return [...queue].sort(compare);\n  }\n \n  function render() {\n    queueEl.innerHTML = \"\";\n    const view = sortedView();\n    if (view.length === 0) {\n      const empty = document.createElement(\"div\");\n      empty.className = \"empty\";\n      empty.textContent = \"— priority queue is empty —\";\n      queueEl.appendChild(empty);\n      return;\n    }\n    view.forEach((item, i) => {\n      const node = document.createElement(\"div\");\n      node.className = \"node\";\n      if (i === 0) node.classList.add(\"next\");\n      node.dataset.id = item.id;\n      node.innerHTML = `\u003Cdiv class=\"value\">${escapeHtml(item.value)}\u003C\u002Fdiv>\n                        \u003Cdiv class=\"prio\">p = ${item.priority}\u003C\u002Fdiv>`;\n      queueEl.appendChild(node);\n    });\n  }\n \n  function escapeHtml(s) {\n    return String(s).replace(\u002F[&\u003C>\"']\u002Fg, c => ({\n      \"&\":\"&amp;\",\"\u003C\":\"&lt;\",\">\":\"&gt;\",\"\\\"\":\"&quot;\",\"'\":\"&#39;\"\n    }[c]));\n  }\n \n  function addItem() {\n    const v = valEl.value.trim();\n    const p = parseInt(prioEl.value, 10);\n    if (!v) { log(\"offer failed — value is empty\", \"err\"); return; }\n    if (Number.isNaN(p)) { log(\"offer failed — priority must be a number\", \"err\"); return; }\n    queue.push({ value: v, priority: p, id: counter++ });\n    log(`offer(\"${v}\", priority=${p})`, \"ok\");\n    valEl.value = \"\"; prioEl.value = \"\";\n    valEl.focus();\n    render();\n  }\n \n  function pollItem() {\n    if (queue.length === 0) { log(\"poll failed — queue is empty\", \"err\"); return; }\n    const sorted = sortedView();\n    const winner = sorted[0];\n    \u002F\u002F Find and animate\n    const winnerNode = queueEl.querySelector(`.node[data-id=\"${winner.id}\"]`);\n    if (winnerNode) {\n      winnerNode.classList.add(\"leaving\");\n      setTimeout(() => {\n        queue = queue.filter(x => x.id !== winner.id);\n        log(`poll() → \"${winner.value}\" (priority ${winner.priority})`, \"ok\");\n        render();\n      }, 380);\n    } else {\n      queue = queue.filter(x => x.id !== winner.id);\n      render();\n    }\n  }\n \n  function clearQ() {\n    if (queue.length === 0) { log(\"queue already empty\", \"info\"); return; }\n    queue = [];\n    log(\"cleared\", \"info\");\n    render();\n  }\n \n  function setMode(m) {\n    mode = m;\n    document.getElementById(\"hiBtn\").classList.toggle(\"active\", m === \"high\");\n    document.getElementById(\"loBtn\").classList.toggle(\"active\", m === \"low\");\n    log(`mode → ${m === \"high\" ? \"larger number wins\" : \"smaller number wins\"}`, \"info\");\n    render();\n  }\n \n  prioEl.addEventListener(\"keydown\", (e) => {\n    if (e.key === \"Enter\") addItem();\n  });\n  valEl.addEventListener(\"keydown\", (e) => {\n    if (e.key === \"Enter\") prioEl.focus();\n  });\n \n  \u002F\u002F Seed with the hospital example\n  [\n    { value: \"Donald\", priority: 3 },\n    { value: \"Chong\",  priority: 1 },\n    { value: \"Ali\",    priority: 2 },\n    { value: \"Bala\",   priority: 4 },\n  ].forEach(x => queue.push({ ...x, id: counter++ }));\n  render();\n  log(\"seeded with 4 patients — Bala has highest priority\", \"info\");\n\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>",[408,938,939],{},[11,940,941],{},[349,942,943],{},"(Try toggling the \"higher = higher priority\" \u002F \"lower = higher priority\" mode at the top — same data, different winner.)",[27,945,947,948],{"id":946},"_8-javas-built-in-priorityqueue","8. Java's built-in ",[42,949,136],{},[11,951,952],{},"Good news: Java ships one. You don't have to build it yourself.",[35,954,956],{"className":433,"code":955,"language":435,"meta":44,"style":44},"import java.util.PriorityQueue;\n",[42,957,958],{"__ignoreMap":44},[439,959,960,963],{"class":441,"line":442},[439,961,962],{"class":445},"import",[439,964,965],{"class":456}," java.util.PriorityQueue;\n",[11,967,968,969,972],{},"It implements the ",[42,970,971],{},"Queue\u003CE>"," interface, so the method names look familiar:",[151,974,975,987],{},[154,976,977],{},[157,978,979,982,984],{},[160,980,981],{},"Method",[160,983,165],{},[160,985,986],{},"Returns",[170,988,989,1004,1023,1038,1052,1066,1080],{},[157,990,991,996,999],{},[175,992,993],{},[42,994,995],{},"offer(E e)",[175,997,998],{},"Add an element",[175,1000,1001],{},[42,1002,1003],{},"boolean",[157,1005,1006,1011,1014],{},[175,1007,1008],{},[42,1009,1010],{},"poll()",[175,1012,1013],{},"Remove and return the highest-priority element",[175,1015,1016,1018,1019,1022],{},[42,1017,460],{}," (or ",[42,1020,1021],{},"null",")",[157,1024,1025,1029,1032],{},[175,1026,1027],{},[42,1028,214],{},[175,1030,1031],{},"Look at the highest-priority element without removing",[175,1033,1034,1018,1036,1022],{},[42,1035,460],{},[42,1037,1021],{},[157,1039,1040,1045,1048],{},[175,1041,1042],{},[42,1043,1044],{},"remove(Object o)",[175,1046,1047],{},"Remove a specific object",[175,1049,1050],{},[42,1051,1003],{},[157,1053,1054,1059,1062],{},[175,1055,1056],{},[42,1057,1058],{},"contains(Object o)",[175,1060,1061],{},"Check if it's in the queue",[175,1063,1064],{},[42,1065,1003],{},[157,1067,1068,1072,1075],{},[175,1069,1070],{},[42,1071,218],{},[175,1073,1074],{},"How many elements",[175,1076,1077],{},[42,1078,1079],{},"int",[157,1081,1082,1087,1090],{},[175,1083,1084],{},[42,1085,1086],{},"clear()",[175,1088,1089],{},"Empty it",[175,1091,1092],{},[42,1093,1094],{},"void",[408,1096,1097],{},[11,1098,1099,273,1102,1105,1106,1105,1109,1112,1113,133,1115,1118,1119,1105,1122,1125],{},[15,1100,1101],{},"A note on naming:",[42,1103,1104],{},"offer"," \u002F ",[42,1107,1108],{},"poll",[42,1110,1111],{},"peek"," are the queue-aware versions that return ",[42,1114,1021],{},[42,1116,1117],{},"false"," instead of throwing on edge cases (empty queue, capacity full). The older ",[42,1120,1121],{},"add",[42,1123,1124],{},"remove"," exist too but can throw exceptions. Prefer the new names.",[232,1127,1129],{"id":1128},"how-does-it-know-what-highest-priority-means","How does it know what \"highest priority\" means?",[11,1131,1132],{},"Two ways:",[1134,1135,1136,1158],"ol",{},[52,1137,1138,1141,1142,358,1145,1147,1148,1150,1151,1154,1155,22],{},[15,1139,1140],{},"Natural ordering."," If your elements implement ",[42,1143,1144],{},"Comparable\u003CE>",[42,1146,136],{}," uses that. For ",[42,1149,733],{},", natural order is alphabetical, so ",[42,1152,1153],{},"\"Georgia\""," comes out before ",[42,1156,1157],{},"\"Texas\"",[52,1159,1160,273,1163,1168],{},[15,1161,1162],{},"Custom",[15,1164,1165,22],{},[42,1166,1167],{},"Comparator"," Pass one to the constructor and you control the order.",[27,1170,1172],{"id":1171},"_9-example-1-strings-two-orderings","9. Example 1 — strings, two orderings",[35,1174,1176],{"className":433,"code":1175,"language":435,"meta":44,"style":44},"import java.util.*;\n \npublic class PriorityQueueDemo {\n  public static void main(String[] args) {\n    \u002F\u002F Default: natural ordering (alphabetical for Strings)\n    PriorityQueue\u003CString> queue1 = new PriorityQueue\u003C>();\n    queue1.offer(\"Oklahoma\");\n    queue1.offer(\"Indiana\");\n    queue1.offer(\"Georgia\");\n    queue1.offer(\"Texas\");\n \n    System.out.println(\"Priority queue using Comparable:\");\n    while (queue1.size() > 0) {\n      System.out.print(queue1.poll() + \" \");\n    }\n    \u002F\u002F → Georgia Indiana Oklahoma Texas\n \n    \u002F\u002F Reversed order via Collections.reverseOrder()\n    PriorityQueue\u003CString> queue2 =\n        new PriorityQueue\u003C>(4, Collections.reverseOrder());\n    queue2.offer(\"Oklahoma\");\n    queue2.offer(\"Indiana\");\n    queue2.offer(\"Georgia\");\n    queue2.offer(\"Texas\");\n \n    System.out.println(\"\\nPriority queue using Comparator:\");\n    while (queue2.size() > 0) {\n      System.out.print(queue2.poll() + \" \");\n    }\n    \u002F\u002F → Texas Oklahoma Indiana Georgia\n  }\n}\n",[42,1177,1178,1192,1196,1208,1233,1238,1255,1269,1282,1294,1306,1310,1324,1345,1368,1372,1377,1381,1386,1398,1418,1432,1445,1458,1471,1476,1496,1514,1534,1539,1545,1551],{"__ignoreMap":44},[439,1179,1180,1182,1185,1189],{"class":441,"line":442},[439,1181,962],{"class":445},[439,1183,1184],{"class":456}," java.util.",[439,1186,1188],{"class":1187},"sj4cs","*",[439,1190,1191],{"class":456},";\n",[439,1193,1194],{"class":441,"line":466},[439,1195,492],{"class":456},[439,1197,1198,1200,1202,1205],{"class":441,"line":489},[439,1199,446],{"class":445},[439,1201,449],{"class":445},[439,1203,1204],{"class":452}," PriorityQueueDemo",[439,1206,1207],{"class":456}," {\n",[439,1209,1210,1213,1216,1218,1221,1223,1225,1228,1231],{"class":441,"line":495},[439,1211,1212],{"class":445},"  public",[439,1214,1215],{"class":445}," static",[439,1217,501],{"class":445},[439,1219,1220],{"class":452}," main",[439,1222,757],{"class":456},[439,1224,733],{"class":445},[439,1226,1227],{"class":456},"[] ",[439,1229,1230],{"class":510},"args",[439,1232,514],{"class":456},[439,1234,1235],{"class":441,"line":517},[439,1236,1237],{"class":529},"    \u002F\u002F Default: natural ordering (alphabetical for Strings)\n",[439,1239,1240,1243,1245,1248,1250,1252],{"class":441,"line":533},[439,1241,1242],{"class":456},"    PriorityQueue\u003C",[439,1244,733],{"class":445},[439,1246,1247],{"class":456},"> queue1 ",[439,1249,480],{"class":445},[439,1251,483],{"class":445},[439,1253,1254],{"class":456}," PriorityQueue\u003C>();\n",[439,1256,1257,1260,1262,1264,1267],{"class":441,"line":539},[439,1258,1259],{"class":456},"    queue1.",[439,1261,1104],{"class":452},[439,1263,757],{"class":456},[439,1265,1266],{"class":648},"\"Oklahoma\"",[439,1268,797],{"class":456},[439,1270,1271,1273,1275,1277,1280],{"class":441,"line":544},[439,1272,1259],{"class":456},[439,1274,1104],{"class":452},[439,1276,757],{"class":456},[439,1278,1279],{"class":648},"\"Indiana\"",[439,1281,797],{"class":456},[439,1283,1284,1286,1288,1290,1292],{"class":441,"line":557},[439,1285,1259],{"class":456},[439,1287,1104],{"class":452},[439,1289,757],{"class":456},[439,1291,1153],{"class":648},[439,1293,797],{"class":456},[439,1295,1296,1298,1300,1302,1304],{"class":441,"line":575},[439,1297,1259],{"class":456},[439,1299,1104],{"class":452},[439,1301,757],{"class":456},[439,1303,1157],{"class":648},[439,1305,797],{"class":456},[439,1307,1308],{"class":441,"line":580},[439,1309,492],{"class":456},[439,1311,1312,1315,1317,1319,1322],{"class":441,"line":585},[439,1313,1314],{"class":456},"    System.out.",[439,1316,826],{"class":452},[439,1318,757],{"class":456},[439,1320,1321],{"class":648},"\"Priority queue using Comparable:\"",[439,1323,797],{"class":456},[439,1325,1326,1329,1332,1334,1337,1340,1343],{"class":441,"line":598},[439,1327,1328],{"class":445},"    while",[439,1330,1331],{"class":456}," (queue1.",[439,1333,605],{"class":452},[439,1335,1336],{"class":456},"() ",[439,1338,1339],{"class":445},">",[439,1341,1342],{"class":1187}," 0",[439,1344,514],{"class":456},[439,1346,1347,1350,1353,1356,1358,1360,1363,1366],{"class":441,"line":611},[439,1348,1349],{"class":456},"      System.out.",[439,1351,1352],{"class":452},"print",[439,1354,1355],{"class":456},"(queue1.",[439,1357,1108],{"class":452},[439,1359,1336],{"class":456},[439,1361,1362],{"class":445},"+",[439,1364,1365],{"class":648}," \" \"",[439,1367,797],{"class":456},[439,1369,1370],{"class":441,"line":616},[439,1371,536],{"class":456},[439,1373,1374],{"class":441,"line":621},[439,1375,1376],{"class":529},"    \u002F\u002F → Georgia Indiana Oklahoma Texas\n",[439,1378,1379],{"class":441,"line":630},[439,1380,492],{"class":456},[439,1382,1383],{"class":441,"line":643},[439,1384,1385],{"class":529},"    \u002F\u002F Reversed order via Collections.reverseOrder()\n",[439,1387,1388,1390,1392,1395],{"class":441,"line":661},[439,1389,1242],{"class":456},[439,1391,733],{"class":445},[439,1393,1394],{"class":456},"> queue2 ",[439,1396,1397],{"class":445},"=\n",[439,1399,1400,1403,1406,1409,1412,1415],{"class":441,"line":666},[439,1401,1402],{"class":445},"        new",[439,1404,1405],{"class":456}," PriorityQueue\u003C>(",[439,1407,1408],{"class":1187},"4",[439,1410,1411],{"class":456},", Collections.",[439,1413,1414],{"class":452},"reverseOrder",[439,1416,1417],{"class":456},"());\n",[439,1419,1421,1424,1426,1428,1430],{"class":441,"line":1420},21,[439,1422,1423],{"class":456},"    queue2.",[439,1425,1104],{"class":452},[439,1427,757],{"class":456},[439,1429,1266],{"class":648},[439,1431,797],{"class":456},[439,1433,1435,1437,1439,1441,1443],{"class":441,"line":1434},22,[439,1436,1423],{"class":456},[439,1438,1104],{"class":452},[439,1440,757],{"class":456},[439,1442,1279],{"class":648},[439,1444,797],{"class":456},[439,1446,1448,1450,1452,1454,1456],{"class":441,"line":1447},23,[439,1449,1423],{"class":456},[439,1451,1104],{"class":452},[439,1453,757],{"class":456},[439,1455,1153],{"class":648},[439,1457,797],{"class":456},[439,1459,1461,1463,1465,1467,1469],{"class":441,"line":1460},24,[439,1462,1423],{"class":456},[439,1464,1104],{"class":452},[439,1466,757],{"class":456},[439,1468,1157],{"class":648},[439,1470,797],{"class":456},[439,1472,1474],{"class":441,"line":1473},25,[439,1475,492],{"class":456},[439,1477,1479,1481,1483,1485,1488,1491,1494],{"class":441,"line":1478},26,[439,1480,1314],{"class":456},[439,1482,826],{"class":452},[439,1484,757],{"class":456},[439,1486,1487],{"class":648},"\"",[439,1489,1490],{"class":1187},"\\n",[439,1492,1493],{"class":648},"Priority queue using Comparator:\"",[439,1495,797],{"class":456},[439,1497,1499,1501,1504,1506,1508,1510,1512],{"class":441,"line":1498},27,[439,1500,1328],{"class":445},[439,1502,1503],{"class":456}," (queue2.",[439,1505,605],{"class":452},[439,1507,1336],{"class":456},[439,1509,1339],{"class":445},[439,1511,1342],{"class":1187},[439,1513,514],{"class":456},[439,1515,1517,1519,1521,1524,1526,1528,1530,1532],{"class":441,"line":1516},28,[439,1518,1349],{"class":456},[439,1520,1352],{"class":452},[439,1522,1523],{"class":456},"(queue2.",[439,1525,1108],{"class":452},[439,1527,1336],{"class":456},[439,1529,1362],{"class":445},[439,1531,1365],{"class":648},[439,1533,797],{"class":456},[439,1535,1537],{"class":441,"line":1536},29,[439,1538,536],{"class":456},[439,1540,1542],{"class":441,"line":1541},30,[439,1543,1544],{"class":529},"    \u002F\u002F → Texas Oklahoma Indiana Georgia\n",[439,1546,1548],{"class":441,"line":1547},31,[439,1549,1550],{"class":456},"  }\n",[439,1552,1554],{"class":441,"line":1553},32,[439,1555,669],{"class":456},[11,1557,1558,1559,22],{},"Same elements, opposite outputs — just by swapping in ",[42,1560,1561],{},"Collections.reverseOrder()",[27,1563,1565],{"id":1564},"_10-example-2-your-own-objects","10. Example 2 — your own objects",[11,1567,1568,1569,1572],{},"What if you want to queue something Java doesn't know how to compare? Like a ",[42,1570,1571],{},"Customer","?",[11,1574,1575,1576,1579,1580,88],{},"You have to teach it. Implement ",[42,1577,1578],{},"Comparable\u003CCustomer>"," and define ",[42,1581,1582],{},"compareTo",[35,1584,1586],{"className":433,"code":1585,"language":435,"meta":44,"style":44},"public class Customer implements Comparable\u003CCustomer> {\n  private Integer id;\n  private String name;\n \n  public Customer(Integer id, String name) {\n    this.id = id;\n    this.name = name;\n  }\n \n  public Integer getID() { return id; }\n  public String  getName() { return name; }\n \n  @Override\n  public int compareTo(Customer c) {\n    return this.getID().compareTo(c.getID());\n  }\n \n  @Override\n  public String toString() {\n    return \"Customer [id=\" + id + \", name=\" + name + \"]\";\n  }\n}\n",[42,1587,1588,1609,1617,1624,1628,1648,1661,1673,1677,1681,1700,1717,1721,1728,1745,1769,1773,1777,1783,1793,1822,1826],{"__ignoreMap":44},[439,1589,1590,1592,1594,1597,1600,1603,1605,1607],{"class":441,"line":442},[439,1591,446],{"class":445},[439,1593,449],{"class":445},[439,1595,1596],{"class":452}," Customer",[439,1598,1599],{"class":445}," implements",[439,1601,1602],{"class":452}," Comparable",[439,1604,457],{"class":456},[439,1606,1571],{"class":445},[439,1608,463],{"class":456},[439,1610,1611,1614],{"class":441,"line":466},[439,1612,1613],{"class":445},"  private",[439,1615,1616],{"class":456}," Integer id;\n",[439,1618,1619,1621],{"class":441,"line":489},[439,1620,1613],{"class":445},[439,1622,1623],{"class":456}," String name;\n",[439,1625,1626],{"class":441,"line":495},[439,1627,492],{"class":456},[439,1629,1630,1632,1634,1637,1640,1643,1646],{"class":441,"line":517},[439,1631,1212],{"class":445},[439,1633,1596],{"class":452},[439,1635,1636],{"class":456},"(Integer ",[439,1638,1639],{"class":510},"id",[439,1641,1642],{"class":456},", String ",[439,1644,1645],{"class":510},"name",[439,1647,514],{"class":456},[439,1649,1650,1653,1656,1658],{"class":441,"line":533},[439,1651,1652],{"class":1187},"    this",[439,1654,1655],{"class":456},".id ",[439,1657,480],{"class":445},[439,1659,1660],{"class":456}," id;\n",[439,1662,1663,1665,1668,1670],{"class":441,"line":539},[439,1664,1652],{"class":1187},[439,1666,1667],{"class":456},".name ",[439,1669,480],{"class":445},[439,1671,1672],{"class":456}," name;\n",[439,1674,1675],{"class":441,"line":544},[439,1676,1550],{"class":456},[439,1678,1679],{"class":441,"line":557},[439,1680,492],{"class":456},[439,1682,1683,1685,1688,1691,1694,1697],{"class":441,"line":575},[439,1684,1212],{"class":445},[439,1686,1687],{"class":456}," Integer ",[439,1689,1690],{"class":452},"getID",[439,1692,1693],{"class":456},"() { ",[439,1695,1696],{"class":445},"return",[439,1698,1699],{"class":456}," id; }\n",[439,1701,1702,1704,1707,1710,1712,1714],{"class":441,"line":580},[439,1703,1212],{"class":445},[439,1705,1706],{"class":456}," String  ",[439,1708,1709],{"class":452},"getName",[439,1711,1693],{"class":456},[439,1713,1696],{"class":445},[439,1715,1716],{"class":456}," name; }\n",[439,1718,1719],{"class":441,"line":585},[439,1720,492],{"class":456},[439,1722,1723,1726],{"class":441,"line":598},[439,1724,1725],{"class":456},"  @",[439,1727,627],{"class":445},[439,1729,1730,1732,1734,1737,1740,1743],{"class":441,"line":611},[439,1731,1212],{"class":445},[439,1733,590],{"class":445},[439,1735,1736],{"class":452}," compareTo",[439,1738,1739],{"class":456},"(Customer ",[439,1741,1742],{"class":510},"c",[439,1744,514],{"class":456},[439,1746,1747,1750,1753,1755,1757,1760,1762,1765,1767],{"class":441,"line":616},[439,1748,1749],{"class":445},"    return",[439,1751,1752],{"class":1187}," this",[439,1754,22],{"class":456},[439,1756,1690],{"class":452},[439,1758,1759],{"class":456},"().",[439,1761,1582],{"class":452},[439,1763,1764],{"class":456},"(c.",[439,1766,1690],{"class":452},[439,1768,1417],{"class":456},[439,1770,1771],{"class":441,"line":621},[439,1772,1550],{"class":456},[439,1774,1775],{"class":441,"line":630},[439,1776,492],{"class":456},[439,1778,1779,1781],{"class":441,"line":643},[439,1780,1725],{"class":456},[439,1782,627],{"class":445},[439,1784,1785,1787,1789,1791],{"class":441,"line":661},[439,1786,1212],{"class":445},[439,1788,635],{"class":456},[439,1790,638],{"class":452},[439,1792,554],{"class":456},[439,1794,1795,1797,1800,1802,1805,1807,1810,1812,1815,1817,1820],{"class":441,"line":666},[439,1796,1749],{"class":445},[439,1798,1799],{"class":648}," \"Customer [id=\"",[439,1801,652],{"class":445},[439,1803,1804],{"class":456}," id ",[439,1806,1362],{"class":445},[439,1808,1809],{"class":648}," \", name=\"",[439,1811,652],{"class":445},[439,1813,1814],{"class":456}," name ",[439,1816,1362],{"class":445},[439,1818,1819],{"class":648}," \"]\"",[439,1821,1191],{"class":456},[439,1823,1824],{"class":441,"line":1420},[439,1825,1550],{"class":456},[439,1827,1828],{"class":441,"line":1434},[439,1829,669],{"class":456},[11,1831,1832,1833,1835,1836,1838],{},"Now you can drop ",[42,1834,1571],{}," objects into a ",[42,1837,136],{}," and it'll know what to do:",[35,1840,1842],{"className":433,"code":1841,"language":435,"meta":44,"style":44},"PriorityQueue\u003CCustomer> customerQueue =\n    new PriorityQueue\u003C>(Collections.reverseOrder());\n \ncustomerQueue.add(new Customer(3, \"Donald\"));\ncustomerQueue.add(new Customer(1, \"Chong\"));\ncustomerQueue.add(new Customer(2, \"Ali\"));\ncustomerQueue.add(new Customer(4, \"Bala\"));\n \nCustomer c = customerQueue.peek();\nif (c != null) {\n  System.out.println(c.getName() + \" is in the queue\");\n  while ((c = customerQueue.poll()) != null) {\n    System.out.println(c);\n  }\n}\n",[42,1843,1844,1856,1868,1872,1899,1923,1947,1970,1974,1988,2004,2024,2047,2056,2060],{"__ignoreMap":44},[439,1845,1846,1849,1851,1854],{"class":441,"line":442},[439,1847,1848],{"class":456},"PriorityQueue\u003C",[439,1850,1571],{"class":445},[439,1852,1853],{"class":456},"> customerQueue ",[439,1855,1397],{"class":445},[439,1857,1858,1861,1864,1866],{"class":441,"line":466},[439,1859,1860],{"class":445},"    new",[439,1862,1863],{"class":456}," PriorityQueue\u003C>(Collections.",[439,1865,1414],{"class":452},[439,1867,1417],{"class":456},[439,1869,1870],{"class":441,"line":489},[439,1871,492],{"class":456},[439,1873,1874,1877,1879,1881,1884,1886,1888,1891,1893,1896],{"class":441,"line":495},[439,1875,1876],{"class":456},"customerQueue.",[439,1878,1121],{"class":452},[439,1880,757],{"class":456},[439,1882,1883],{"class":445},"new",[439,1885,1596],{"class":452},[439,1887,757],{"class":456},[439,1889,1890],{"class":1187},"3",[439,1892,358],{"class":456},[439,1894,1895],{"class":648},"\"Donald\"",[439,1897,1898],{"class":456},"));\n",[439,1900,1901,1903,1905,1907,1909,1911,1913,1916,1918,1921],{"class":441,"line":517},[439,1902,1876],{"class":456},[439,1904,1121],{"class":452},[439,1906,757],{"class":456},[439,1908,1883],{"class":445},[439,1910,1596],{"class":452},[439,1912,757],{"class":456},[439,1914,1915],{"class":1187},"1",[439,1917,358],{"class":456},[439,1919,1920],{"class":648},"\"Chong\"",[439,1922,1898],{"class":456},[439,1924,1925,1927,1929,1931,1933,1935,1937,1940,1942,1945],{"class":441,"line":533},[439,1926,1876],{"class":456},[439,1928,1121],{"class":452},[439,1930,757],{"class":456},[439,1932,1883],{"class":445},[439,1934,1596],{"class":452},[439,1936,757],{"class":456},[439,1938,1939],{"class":1187},"2",[439,1941,358],{"class":456},[439,1943,1944],{"class":648},"\"Ali\"",[439,1946,1898],{"class":456},[439,1948,1949,1951,1953,1955,1957,1959,1961,1963,1965,1968],{"class":441,"line":539},[439,1950,1876],{"class":456},[439,1952,1121],{"class":452},[439,1954,757],{"class":456},[439,1956,1883],{"class":445},[439,1958,1596],{"class":452},[439,1960,757],{"class":456},[439,1962,1408],{"class":1187},[439,1964,358],{"class":456},[439,1966,1967],{"class":648},"\"Bala\"",[439,1969,1898],{"class":456},[439,1971,1972],{"class":441,"line":544},[439,1973,492],{"class":456},[439,1975,1976,1979,1981,1984,1986],{"class":441,"line":557},[439,1977,1978],{"class":456},"Customer c ",[439,1980,480],{"class":445},[439,1982,1983],{"class":456}," customerQueue.",[439,1985,1111],{"class":452},[439,1987,608],{"class":456},[439,1989,1990,1993,1996,1999,2002],{"class":441,"line":575},[439,1991,1992],{"class":445},"if",[439,1994,1995],{"class":456}," (c ",[439,1997,1998],{"class":445},"!=",[439,2000,2001],{"class":1187}," null",[439,2003,514],{"class":456},[439,2005,2006,2009,2011,2013,2015,2017,2019,2022],{"class":441,"line":580},[439,2007,2008],{"class":456},"  System.out.",[439,2010,826],{"class":452},[439,2012,1764],{"class":456},[439,2014,1709],{"class":452},[439,2016,1336],{"class":456},[439,2018,1362],{"class":445},[439,2020,2021],{"class":648}," \" is in the queue\"",[439,2023,797],{"class":456},[439,2025,2026,2029,2032,2034,2036,2038,2041,2043,2045],{"class":441,"line":585},[439,2027,2028],{"class":445},"  while",[439,2030,2031],{"class":456}," ((c ",[439,2033,480],{"class":445},[439,2035,1983],{"class":456},[439,2037,1108],{"class":452},[439,2039,2040],{"class":456},"()) ",[439,2042,1998],{"class":445},[439,2044,2001],{"class":1187},[439,2046,514],{"class":456},[439,2048,2049,2051,2053],{"class":441,"line":598},[439,2050,1314],{"class":456},[439,2052,826],{"class":452},[439,2054,2055],{"class":456},"(c);\n",[439,2057,2058],{"class":441,"line":611},[439,2059,1550],{"class":456},[439,2061,2062],{"class":441,"line":616},[439,2063,669],{"class":456},[11,2065,2066],{},"Output:",[35,2068,2071],{"className":2069,"code":2070,"language":40},[38],"Bala is in the queue\nCustomer [id=4, name=Bala]\nCustomer [id=3, name=Donald]\nCustomer [id=2, name=Ali]\nCustomer [id=1, name=Chong]\n",[42,2072,2070],{"__ignoreMap":44},[11,2074,2075,2076,2079,2080,2083],{},"Because we used ",[42,2077,2078],{},"reverseOrder()",", the ",[15,2081,2082],{},"biggest id wins",". Bala (id=4) is the VIP.",[408,2085,2086,2095,2118],{},[11,2087,2088,273,2092],{},[15,2089,2090],{},[42,2091,1582],{},[15,2093,2094],{},"cheat sheet:",[49,2096,2097,2107,2110],{},[52,2098,2099,2100,2103,2104],{},"Returns negative → ",[42,2101,2102],{},"this"," is \"less than\" ",[42,2105,2106],{},"other",[52,2108,2109],{},"Returns zero → equal priority",[52,2111,2112,2113,2115,2116],{},"Returns positive → ",[42,2114,2102],{}," is \"greater than\" ",[42,2117,2106],{},[11,2119,2120,2121,2123],{},"By default, \"greater\" = \"later out\". Reverse it with a ",[42,2122,1167],{}," if you want the largest first.",[27,2125,2127],{"id":2126},"_11-quick-check-can-you-answer-these","11. Quick check — can you answer these?",[11,2129,2130],{},"Before moving on, see if you can answer these without scrolling back up.",[1134,2132,2133,2136,2139,2148,2155],{},[52,2134,2135],{},"Where in a queue do you insert? Where do you delete?",[52,2137,2138],{},"What does FIFO stand for?",[52,2140,2141,2142,2144,2145,2147],{},"Why is a ",[42,2143,132],{}," a better choice than an ",[42,2146,260],{}," to implement a queue?",[52,2149,2150,2151,2154],{},"What are the two preferred methods to add and remove in ",[42,2152,2153],{},"java.util.PriorityQueue"," (the ones that don't throw)?",[52,2156,2157,2158,2161,2162,2165,2166,2168],{},"If you put ",[42,2159,2160],{},"5, 1, 8, 3"," into a default ",[42,2163,2164],{},"PriorityQueue\u003CInteger>"," and call ",[42,2167,1010],{}," four times, what comes out and in what order?",[11,2170,2171],{},"Answers",[1134,2173,2174,2177,2180,2186,2195],{},[52,2175,2176],{},"Insert at the rear (back\u002Ftail). Delete from the front (head).",[52,2178,2179],{},"First In, First Out.",[52,2181,2182,2183,2185],{},"Removing from the front of an ",[42,2184,260],{}," is O(n) because every other element has to shift. With a doubly-linked list, head removal is O(1).",[52,2187,2188,2191,2192,2194],{},[42,2189,2190],{},"offer(e)"," to add, ",[42,2193,1010],{}," to remove.",[52,2196,2197,2200,2201,2204],{},[42,2198,2199],{},"1, 3, 5, 8"," — natural ordering for ",[42,2202,2203],{},"Integer"," is ascending, so smallest comes out first.",[27,2206,2208],{"id":2207},"_12-exercise-build-your-own","12. Exercise — build your own",[11,2210,2211,2212,2215,2216,2219],{},"Want a workout? Try implementing a queue using an ",[15,2213,2214],{},"array"," instead of a linked list. Call it ",[42,2217,2218],{},"ArrayQueue\u003CE>",". You'll need to think about:",[49,2221,2222,2225,2242],{},[52,2223,2224],{},"Two index pointers — one for the front, one for the rear.",[52,2226,2227,2228,2230,2231,2234,2235,2237,2238,2241],{},"What happens when ",[42,2229,192],{}," reaches the end of the array? (Hint: a ",[15,2232,2233],{},"circular array"," wraps ",[42,2236,192],{}," back to ",[42,2239,2240],{},"0",".)",[52,2243,2244,2245,2248],{},"How and when to ",[42,2246,2247],{},"resize()"," when the array fills up.\nSketch of the API:",[35,2250,2252],{"className":433,"code":2251,"language":435,"meta":44,"style":44},"public class ArrayQueue\u003CE> {\n    public ArrayQueue();\n    public ArrayQueue(int initialCapacity);\n    public void enqueue(E e);\n    public E    dequeue();\n    public E    getElement();   \u002F\u002F peek\n    public boolean isEmpty();\n    public int  size();\n    private void resize();      \u002F\u002F grow when full\n}\n",[42,2253,2254,2269,2277,2292,2306,2317,2332,2344,2355,2370],{"__ignoreMap":44},[439,2255,2256,2258,2260,2263,2265,2267],{"class":441,"line":442},[439,2257,446],{"class":445},[439,2259,449],{"class":445},[439,2261,2262],{"class":452}," ArrayQueue",[439,2264,457],{"class":456},[439,2266,460],{"class":445},[439,2268,463],{"class":456},[439,2270,2271,2273,2275],{"class":441,"line":466},[439,2272,498],{"class":445},[439,2274,2262],{"class":452},[439,2276,608],{"class":456},[439,2278,2279,2281,2283,2285,2287,2290],{"class":441,"line":489},[439,2280,498],{"class":445},[439,2282,2262],{"class":452},[439,2284,757],{"class":456},[439,2286,1079],{"class":445},[439,2288,2289],{"class":510}," initialCapacity",[439,2291,797],{"class":456},[439,2293,2294,2296,2298,2300,2302,2304],{"class":441,"line":495},[439,2295,498],{"class":445},[439,2297,501],{"class":445},[439,2299,504],{"class":452},[439,2301,507],{"class":456},[439,2303,511],{"class":510},[439,2305,797],{"class":456},[439,2307,2308,2310,2313,2315],{"class":441,"line":517},[439,2309,498],{"class":445},[439,2311,2312],{"class":456}," E    ",[439,2314,229],{"class":452},[439,2316,608],{"class":456},[439,2318,2319,2321,2323,2326,2329],{"class":441,"line":533},[439,2320,498],{"class":445},[439,2322,2312],{"class":456},[439,2324,2325],{"class":452},"getElement",[439,2327,2328],{"class":456},"();   ",[439,2330,2331],{"class":529},"\u002F\u002F peek\n",[439,2333,2334,2336,2339,2342],{"class":441,"line":539},[439,2335,498],{"class":445},[439,2337,2338],{"class":445}," boolean",[439,2340,2341],{"class":452}," isEmpty",[439,2343,608],{"class":456},[439,2345,2346,2348,2350,2353],{"class":441,"line":544},[439,2347,498],{"class":445},[439,2349,590],{"class":445},[439,2351,2352],{"class":452},"  size",[439,2354,608],{"class":456},[439,2356,2357,2359,2361,2364,2367],{"class":441,"line":557},[439,2358,469],{"class":445},[439,2360,501],{"class":445},[439,2362,2363],{"class":452}," resize",[439,2365,2366],{"class":456},"();      ",[439,2368,2369],{"class":529},"\u002F\u002F grow when full\n",[439,2371,2372],{"class":441,"line":575},[439,2373,669],{"class":456},[11,2375,2376],{},"This is a classic interview-style exercise. You learn a lot by getting the circular-array bookkeeping right.",[27,2378,2380],{"id":2379},"_13-where-to-go-next","13. Where to go next",[11,2382,2383],{},"Queues show up everywhere once you start looking — task schedulers, BFS in graph algorithms, print spoolers, message brokers, request handling in web servers. Priority queues power Dijkstra's shortest-path algorithm and A* search. The simple FIFO idea is doing a lot of work behind the scenes in real systems.",[11,2385,2386,2387,2390],{},"Coming up next in this series: ",[15,2388,2389],{},"trees"," — the structure that makes priority queues fast under the hood (via something called a binary heap), and a whole lot more.",[2392,2393,2394],"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 .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}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}",{"title":44,"searchDepth":466,"depth":466,"links":2396},[2397,2398,2399,2402,2403,2410,2414,2417,2421,2422,2423,2424,2425],{"id":29,"depth":466,"text":30},{"id":76,"depth":466,"text":77},{"id":145,"depth":466,"text":146,"children":2400},[2401],{"id":234,"depth":489,"text":235},{"id":253,"depth":466,"text":254},{"id":315,"depth":466,"text":2404,"children":2405},"5. Two ways to wire a GenericQueue to a LinkedList",[2406,2408],{"id":328,"depth":489,"text":2407},"Option A: Inheritance — GenericQueue extends LinkedList",{"id":365,"depth":489,"text":2409},"Option B: Composition — GenericQueue has-a LinkedList",{"id":422,"depth":466,"text":2411,"children":2412},"6. GenericQueue\u003CE> — the code",[2413],{"id":719,"depth":489,"text":720},{"id":878,"depth":466,"text":879,"children":2415},[2416],{"id":921,"depth":489,"text":922},{"id":946,"depth":466,"text":2418,"children":2419},"8. Java's built-in PriorityQueue",[2420],{"id":1128,"depth":489,"text":1129},{"id":1171,"depth":466,"text":1172},{"id":1564,"depth":466,"text":1565},{"id":2126,"depth":466,"text":2127},{"id":2207,"depth":466,"text":2208},{"id":2379,"depth":466,"text":2380},"2026-05-14","If you've ever stood in line at a bubble tea shop, you already understand a queue. That's basically the whole idea — but in code, this simple concept turns into one of the most useful data structures you'll meet. In this post we'll walk through what a queue is, how to implement one in Java, and then level it up into a priority queue.",false,"md",null,{},true,"\u002Fblog\u002FQueues",{"title":5,"description":2427},{"loc":2433},"blog\u002FQueues","FFeB3KJM4Klz1PpsvA6T9_hsr_D6m22PP0ly80ppz_g",117,{"id":2440,"extension":2441,"meta":2442,"series":2443,"stem":2553,"__hash__":2554},"series\u002Fseries.json","json",{},{"微積分教學":2444,"生活紀錄":2447,"Motor Control":2449,"生活隨筆":2463,"Motor learning":2467,"小兒物治":2485,"中風":2500,"平衡":2513,"Network Communication":2523,"CSA":2530,"機器學習":2536,"小腦":2540,"SCI脊髓損傷":2549},[2445,2446],"微積分隨筆-未完成版","2025數學回顧",[2448],"一個漂流到地球的故事",[2450,2451,2452,2453,2454,2455,2456,2457,2458,2459,2460,2461,2462],"控制自己-Be-water-my-friend","控制自己-Be-water-my-friend（二）","控制自己-Be-water-my-friend（三）","控制自己-Be-water-my-friend（四）","控制自己-Be-water-my-friend（五）","進階控制制制制","周圍理論學派（一）反射理論","周圍理論學派（二）階層理論","中樞理論學派（一）CPG","中樞理論學派（二）Motor-Program","模組理論","系統理論","動態模組理論",[2464,2465,2466],"你好，世界。","根本沒人在乎你的部落格","早安-午安-晚安",[2468,2469,2470,2471,2472,2473,2474,2475,2476,2477,2478,2479,2480,2481,2482,2483,2484],"動作學習（一）介紹","動作學習（二）form-of-learning","動作學習（三）Measurement-of-learning","動作學習（四）理論","動作學習（五）理論-2","動作學習（六）理論-3","動作學習（七）練習方式-1","動作學習（八）練習方式-2","動作學習（九）回饋-1","動作學習（十）回饋-2-擴增性(KR)","動作學習（十一）回饋-3-擴增性(KP)","動作學習（十一）回饋-4-(間隔+物理引導)","動作學習（十二）神經可塑性","動作學習（十二）神經可塑性2","動作學習（十三）臨床應用","動作學習（十四）記憶","動作學習（十五）影響表現的因素",[2486,2487,2488,2489,2490,2491,2492,2493,2494,2495,2496,2497,2498,2499],"腦性痲痺-CP","CP補充（一）","CP—Rood-&-Bobath","CP—Rood-&-Bobath（二）","Motor-Learning","Motor-Learning小兒（二）","Gait-analysis小兒（一）","Gait-analysis小兒（二）","小兒發展（一）","小兒發展（二）","小兒發展（三）","小兒發展（四）","小兒發展（五）","GMFCS",[2501,2502,2503,2504,2505,2506,2507,2508,2509,2510,2511,2512],"腦血管病變（CVA）（中風）(一)","CVA（二）","CVA（三）血管症候群-i","CVA（四）血管症候群-(ii)","CVA（四）","CVA（六）","CVA（七）評估-(i)","CVA（八）評估-(ii)","CVA（九）復健—手部-(i)","CVA（十）功能性走路","CVA（十一）功能性走路ii","CVA（十二）輔助用品",[2514,2515,2516,2517,2518,2519,2520,2521,2522],"平衡與前庭失調（一）","Balance（二）前庭覺-(i)","Balance（三）","Balance（四）評估","Balance（五）復健","Balance（六）功能恢復","Balance（七）前庭障礙","Balance（八）檢查","Balance（九）干預",[2524,2525,2526,2527,2528,2529],"Network-Communication,-Chapter-1","Network-Communication,-Chapter-2","Network-Communication,-Chapter-3","Network-Communication-Chapter-4","Network-Communications,-Chapter-5","Network-Communication,-Chapter-6",[2531,2532,2533,2534,2535],"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",[2537,2538,2539],"機器學習導論","資料前處理與迴歸分析","決策樹",[2541,2542,2543,2544,2545,2546,2547,2548],"小腦（一）","小腦（二）","小腦（三）功能","小腦（四）損傷","小腦（五）各功能障礙","小腦（六）評估","小腦（七）評估(ii)","小腦（八）治療",[2550,2551,2552],"脊髓損傷SCI（一）","SCI（二）受傷機制——創傷性（頸椎）","SCI（三）受傷機制--ii","series","OrQkztaCQ8PCQ3c33l2XQ4ZKtA6mZbR3LOKgfR0KR_M",[2556,2575,2595,2614,2631,2648,2663,2680,2698,2720],{"id":2557,"title":2558,"avatar":2559,"banner":2430,"bio":2560,"body":2561,"description":44,"extension":2429,"meta":2565,"name":2558,"navigation":2432,"path":2566,"seo":2567,"sitemap":2568,"social":2569,"stem":2573,"__hash__":2574},"authors\u002Fauthors\u002Fautomata.md","Automata","\u002Fimages\u002Fuploads\u002Fnier-automata-2b.jpg","一隻吐司天喵，漂浮在銀河星辰中",{"type":8,"value":2562,"toc":2563},[],{"title":44,"searchDepth":466,"depth":466,"links":2564},[],{},"\u002Fauthors\u002Fautomata",{"description":44},{"loc":2566},{"website":2570,"twitter":2571,"github":2572},"https:\u002F\u002Freurl.cc\u002FWOeM29","https:\u002F\u002Freurl.cc\u002FLnvLEy","https:\u002F\u002Fgithub.com\u002FAutomata-0","authors\u002Fautomata","IkVbO2zA7revgYq624iVWpSZQUyMmWa82tw_EbWXViE",{"id":2576,"title":2577,"avatar":2578,"banner":2579,"bio":2580,"body":2581,"description":44,"extension":2429,"meta":2585,"name":2586,"navigation":2432,"path":2587,"seo":2588,"sitemap":2589,"social":2590,"stem":2593,"__hash__":2594},"authors\u002Fauthors\u002Fchinono.md","Chinono","\u002Fimages\u002Fuploads\u002F103467998_p0 copy.png","\u002Fimages\u002Fbackground_light.jpg","我不是女生！",{"type":8,"value":2582,"toc":2583},[],{"title":44,"searchDepth":466,"depth":466,"links":2584},[],{},"七糯糯","\u002Fauthors\u002Fchinono",{"description":44},{"loc":2587},{"github":2591,"twitter":44,"website":2592},"https:\u002F\u002Fgithub.com\u002FChinHongTan","https:\u002F\u002Fchinono.dev","authors\u002Fchinono","jj1J9mFh3InZFL6XtCzGBQ5jPip0EwBDE3mjGvnN6jE",{"id":2596,"title":2597,"avatar":2598,"banner":2599,"bio":2600,"body":2601,"description":44,"extension":2429,"meta":2605,"name":2606,"navigation":2432,"path":2607,"seo":2608,"sitemap":2609,"social":2610,"stem":2612,"__hash__":2613},"authors\u002Fauthors\u002Fhibiki12141132.md","Hibiki12141132","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F265822020?v=4","\u002Fimages\u002Fuploads\u002F1773978423557-___.jpg","享受著知識強姦大腦的過程 (內文含個人發癲 不要再意)",{"type":8,"value":2602,"toc":2603},[],{"title":44,"searchDepth":466,"depth":466,"links":2604},[],{},"HiBiKi","\u002Fauthors\u002Fhibiki12141132",{"description":44},{"loc":2607},{"github":2611,"twitter":44},"https:\u002F\u002Fgithub.com\u002FHiBiKi12141132","authors\u002Fhibiki12141132","dbRnKEcYeCH_faD8R7AUmPPcwgc26s_fR4Q_lu4qtA4",{"id":2615,"title":2616,"avatar":2617,"banner":2430,"bio":2618,"body":2619,"description":44,"extension":2429,"meta":2623,"name":2616,"navigation":2432,"path":2624,"seo":2625,"sitemap":2626,"social":2627,"stem":2629,"__hash__":2630},"authors\u002Fauthors\u002Fmahiro.md","Mahiro","https:\u002F\u002Ftruth.bahamut.com.tw\u002Fs01\u002F202601\u002F2a29b047d341f840b2ce89f7d65b2ba3.JPG","一個致力於逃離新竹的電機系小雜魚",{"type":8,"value":2620,"toc":2621},[],{"title":44,"searchDepth":466,"depth":466,"links":2622},[],{},"\u002Fauthors\u002Fmahiro",{"description":44},{"loc":2624},{"github":2628},"https:\u002F\u002Fgithub.com\u002Fwifekurumi","authors\u002Fmahiro","b435tdWu9eXUf06WroCge0I405cqA0FhLlUUhoPk14k",{"id":2632,"title":2633,"avatar":2634,"banner":2430,"bio":2635,"body":2636,"description":44,"extension":2429,"meta":2640,"name":2633,"navigation":2432,"path":2641,"seo":2642,"sitemap":2643,"social":2644,"stem":2646,"__hash__":2647},"authors\u002Fauthors\u002Fosborrrrn.md","Osborrrrn","\u002Fimages\u002Fuploads\u002Frectangle_large_type_2_c516437ed713e5de1f7d2dca8a20cd81.jpg","別人笑我太瘋癲，我笑他人看不穿。\n不見五陵豪傑墓，無花無酒鋤就田",{"type":8,"value":2637,"toc":2638},[],{"title":44,"searchDepth":466,"depth":466,"links":2639},[],{},"\u002Fauthors\u002Fosborrrrn",{"description":44},{"loc":2641},{"github":2645},"https:\u002F\u002Fgithub.com\u002FOsborrrrn","authors\u002Fosborrrrn","w6VWZKPUwvXn5i7MKXOpU2Jeqr3BrdTKVCeDOF2jZlU",{"id":2649,"title":2650,"avatar":2430,"banner":2430,"bio":2651,"body":2652,"description":44,"extension":2429,"meta":2656,"name":2650,"navigation":2432,"path":2657,"seo":2658,"sitemap":2659,"social":2660,"stem":2661,"__hash__":2662},"authors\u002Fauthors\u002F法法.md","法法","123",{"type":8,"value":2653,"toc":2654},[],{"title":44,"searchDepth":466,"depth":466,"links":2655},[],{},"\u002Fauthors\u002F法法",{"description":44},{"loc":2657},{"github":44},"authors\u002F法法","o5pdVuPCfTmhkDCpvgy4YmAP0CGdvFluPvjhgvQVbsI",{"id":2664,"title":2665,"avatar":2666,"banner":2430,"bio":2667,"body":2668,"description":44,"extension":2429,"meta":2672,"name":2665,"navigation":2432,"path":2673,"seo":2674,"sitemap":2675,"social":2676,"stem":2678,"__hash__":2679},"authors\u002Fauthors\u002F灰海獅.md","灰海獅","\u002Fimages\u002Fuploads\u002Fimg_3279.jpeg","守夜人",{"type":8,"value":2669,"toc":2670},[],{"title":44,"searchDepth":466,"depth":466,"links":2671},[],{},"\u002Fauthors\u002F灰海獅",{"description":44},{"loc":2673},{"github":2677},"https:\u002F\u002Fgithub.com\u002Fyuiri333","authors\u002F灰海獅","iZoSIFbQdS-6v3LiK1txgxnIMKy-d2CyZXQk9CMua_s",{"id":2681,"title":2682,"avatar":2683,"banner":2684,"bio":2685,"body":2686,"description":44,"extension":2429,"meta":2690,"name":2682,"navigation":2432,"path":2691,"seo":2692,"sitemap":2693,"social":2694,"stem":2696,"__hash__":2697},"authors\u002Fauthors\u002F花夜.md","花夜","\u002Fimages\u002Fuploads\u002F1772719470518-791_20260218161129.png","\u002Fimages\u002Fuploads\u002Fimg_2446.png","無論你身在何處，我都會在這裡等你",{"type":8,"value":2687,"toc":2688},[],{"title":44,"searchDepth":466,"depth":466,"links":2689},[],{},"\u002Fauthors\u002F花夜",{"description":44},{"loc":2691},{"github":2695,"twitter":44},"https:\u002F\u002Fgithub.com\u002Fflowernight0709","authors\u002F花夜","a7jeQiF_JkawgYIR-aYSGceJdDP6Z-OWydsICvgSIzs",{"id":2699,"title":2700,"avatar":2701,"banner":2702,"bio":2703,"body":2704,"description":2708,"extension":2429,"meta":2711,"name":2700,"navigation":2432,"path":2712,"seo":2713,"sitemap":2714,"social":2715,"stem":2718,"__hash__":2719},"authors\u002Fauthors\u002F輝月.md","輝月","\u002Fimages\u002Fuploads\u002Ffb_img_1771085634823.jpg","\u002Fimages\u002Fuploads\u002Fimg_1751.jpg","天下布魔好好玩",{"type":8,"value":2705,"toc":2709},[2706],[11,2707,2708],{},"準大學生，目前正在製作TFR模組",{"title":44,"searchDepth":466,"depth":466,"links":2710},[],{},"\u002Fauthors\u002F輝月",{"description":2708},{"loc":2712},{"twitter":2716,"github":2717},"https:\u002F\u002Fx.com\u002Fhuiyue945","https:\u002F\u002Fgithub.com\u002Fhuiyueyea","authors\u002F輝月","koUocBihphDy3453-nAcolM7JJYwI7UMBpVkf1JQrMQ",{"id":2721,"title":2722,"avatar":2723,"banner":2430,"bio":2724,"body":2725,"description":2729,"extension":2429,"meta":2742,"name":2722,"navigation":2432,"path":2743,"seo":2744,"sitemap":2745,"social":2746,"stem":2748,"__hash__":2749},"authors\u002Fauthors\u002F阿西狄亞.md","阿西狄亞","\u002Fimages\u002Fuploads\u002Fimg_20251215_121849_589.jpg","君は実に馬鹿だな",{"type":8,"value":2726,"toc":2740},[2727,2730],[11,2728,2729],{},"我是阿西狄亞，阿西狄亞的阿，阿西狄亞的西，阿西狄亞的狄，阿西狄亞的亞，你可以叫我阿西。",[11,2731,2732,2735,2736,2739],{},[15,2733,2734],{},"我說的所有事情都抱有極度主觀的看法以及意見","，如果你有其他想法，",[15,2737,2738],{},"你是對的","。",{"title":44,"searchDepth":466,"depth":466,"links":2741},[],{},"\u002Fauthors\u002F阿西狄亞",{"description":2729},{"loc":2743},{"github":2747},"https:\u002F\u002Fgithub.com\u002FAcedia0130","authors\u002F阿西狄亞","q5ECEDl8-0Y33tPck0lYZnzPjFdJkrOnBN7HkAO3pls",[],[2752,2761,2770,2779,2788,2797,2806,2815,2824,2835],{"id":2557,"title":2558,"avatar":2559,"banner":2430,"bio":2560,"body":2753,"description":44,"extension":2429,"meta":2757,"name":2558,"navigation":2432,"path":2566,"seo":2758,"sitemap":2759,"social":2760,"stem":2573,"__hash__":2574},{"type":8,"value":2754,"toc":2755},[],{"title":44,"searchDepth":466,"depth":466,"links":2756},[],{},{"description":44},{"loc":2566},{"website":2570,"twitter":2571,"github":2572},{"id":2576,"title":2577,"avatar":2578,"banner":2579,"bio":2580,"body":2762,"description":44,"extension":2429,"meta":2766,"name":2586,"navigation":2432,"path":2587,"seo":2767,"sitemap":2768,"social":2769,"stem":2593,"__hash__":2594},{"type":8,"value":2763,"toc":2764},[],{"title":44,"searchDepth":466,"depth":466,"links":2765},[],{},{"description":44},{"loc":2587},{"github":2591,"twitter":44,"website":2592},{"id":2596,"title":2597,"avatar":2598,"banner":2599,"bio":2600,"body":2771,"description":44,"extension":2429,"meta":2775,"name":2606,"navigation":2432,"path":2607,"seo":2776,"sitemap":2777,"social":2778,"stem":2612,"__hash__":2613},{"type":8,"value":2772,"toc":2773},[],{"title":44,"searchDepth":466,"depth":466,"links":2774},[],{},{"description":44},{"loc":2607},{"github":2611,"twitter":44},{"id":2615,"title":2616,"avatar":2617,"banner":2430,"bio":2618,"body":2780,"description":44,"extension":2429,"meta":2784,"name":2616,"navigation":2432,"path":2624,"seo":2785,"sitemap":2786,"social":2787,"stem":2629,"__hash__":2630},{"type":8,"value":2781,"toc":2782},[],{"title":44,"searchDepth":466,"depth":466,"links":2783},[],{},{"description":44},{"loc":2624},{"github":2628},{"id":2632,"title":2633,"avatar":2634,"banner":2430,"bio":2635,"body":2789,"description":44,"extension":2429,"meta":2793,"name":2633,"navigation":2432,"path":2641,"seo":2794,"sitemap":2795,"social":2796,"stem":2646,"__hash__":2647},{"type":8,"value":2790,"toc":2791},[],{"title":44,"searchDepth":466,"depth":466,"links":2792},[],{},{"description":44},{"loc":2641},{"github":2645},{"id":2649,"title":2650,"avatar":2430,"banner":2430,"bio":2651,"body":2798,"description":44,"extension":2429,"meta":2802,"name":2650,"navigation":2432,"path":2657,"seo":2803,"sitemap":2804,"social":2805,"stem":2661,"__hash__":2662},{"type":8,"value":2799,"toc":2800},[],{"title":44,"searchDepth":466,"depth":466,"links":2801},[],{},{"description":44},{"loc":2657},{"github":44},{"id":2664,"title":2665,"avatar":2666,"banner":2430,"bio":2667,"body":2807,"description":44,"extension":2429,"meta":2811,"name":2665,"navigation":2432,"path":2673,"seo":2812,"sitemap":2813,"social":2814,"stem":2678,"__hash__":2679},{"type":8,"value":2808,"toc":2809},[],{"title":44,"searchDepth":466,"depth":466,"links":2810},[],{},{"description":44},{"loc":2673},{"github":2677},{"id":2681,"title":2682,"avatar":2683,"banner":2684,"bio":2685,"body":2816,"description":44,"extension":2429,"meta":2820,"name":2682,"navigation":2432,"path":2691,"seo":2821,"sitemap":2822,"social":2823,"stem":2696,"__hash__":2697},{"type":8,"value":2817,"toc":2818},[],{"title":44,"searchDepth":466,"depth":466,"links":2819},[],{},{"description":44},{"loc":2691},{"github":2695,"twitter":44},{"id":2699,"title":2700,"avatar":2701,"banner":2702,"bio":2703,"body":2825,"description":2708,"extension":2429,"meta":2831,"name":2700,"navigation":2432,"path":2712,"seo":2832,"sitemap":2833,"social":2834,"stem":2718,"__hash__":2719},{"type":8,"value":2826,"toc":2829},[2827],[11,2828,2708],{},{"title":44,"searchDepth":466,"depth":466,"links":2830},[],{},{"description":2708},{"loc":2712},{"twitter":2716,"github":2717},{"id":2721,"title":2722,"avatar":2723,"banner":2430,"bio":2724,"body":2836,"description":2729,"extension":2429,"meta":2848,"name":2722,"navigation":2432,"path":2743,"seo":2849,"sitemap":2850,"social":2851,"stem":2748,"__hash__":2749},{"type":8,"value":2837,"toc":2846},[2838,2840],[11,2839,2729],{},[11,2841,2842,2735,2844,2739],{},[15,2843,2734],{},[15,2845,2738],{},{"title":44,"searchDepth":466,"depth":466,"links":2847},[],{},{"description":2729},{"loc":2743},{"github":2747},1778754114922]