鏈表(C語言)
緒論 單鏈表的實作 單鏈表的定義 單鏈表的初始化 單鏈表的插入洗掉 單鏈表的洗掉 單鏈表的查找 單鏈表的修改 單鏈表的建立
雙向鏈表 回圈鏈表 鏈表與順序表的區別 總結
緒論
線性表是資料結構中比較常見也比較重要的一種線性結構,簡言之,線性表是n個資料元素的有限序列,而線性表又有兩種常見的實作方式,其中比較常考的就是鏈表了, 鏈表實作順序表的時候,與順序表最大不同之處在于,鏈表中兩個邏輯位置在一起的元素,物理地址并不連續,因為鏈表的每個會有一個指向下一項的指標,指標所指地址對應的值才是與該元素邏輯上相鄰的值,本文我們會從單鏈表出發,循序漸進帶大家了解雙鏈表和回圈鏈表, 、
單鏈表的實作
上文我們說到,鏈表里最典型的就是單鏈表了,什么是單鏈表,顧名思義,就是指只有一個指標用來與表中其他元素相對應,
<style>#mermaid-svg-PZHTfGFZYfoOmQnQ .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .label text{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .node rect,#mermaid-svg-PZHTfGFZYfoOmQnQ .node circle,#mermaid-svg-PZHTfGFZYfoOmQnQ .node ellipse,#mermaid-svg-PZHTfGFZYfoOmQnQ .node polygon,#mermaid-svg-PZHTfGFZYfoOmQnQ .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-PZHTfGFZYfoOmQnQ .node .label{text-align:center;fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .node.clickable{cursor:pointer}#mermaid-svg-PZHTfGFZYfoOmQnQ .arrowheadPath{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-PZHTfGFZYfoOmQnQ .flowchart-link{stroke:#333;fill:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-PZHTfGFZYfoOmQnQ .edgeLabel rect{opacity:0.9}#mermaid-svg-PZHTfGFZYfoOmQnQ .edgeLabel span{color:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-PZHTfGFZYfoOmQnQ .cluster text{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-PZHTfGFZYfoOmQnQ .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-PZHTfGFZYfoOmQnQ text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .actor-line{stroke:grey}#mermaid-svg-PZHTfGFZYfoOmQnQ .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .sequenceNumber{fill:#fff}#mermaid-svg-PZHTfGFZYfoOmQnQ #sequencenumber{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ #crosshead path{fill:#333;stroke:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .messageText{fill:#333;stroke:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-PZHTfGFZYfoOmQnQ .labelText,#mermaid-svg-PZHTfGFZYfoOmQnQ .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .loopText,#mermaid-svg-PZHTfGFZYfoOmQnQ .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-PZHTfGFZYfoOmQnQ .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-PZHTfGFZYfoOmQnQ .noteText,#mermaid-svg-PZHTfGFZYfoOmQnQ .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-PZHTfGFZYfoOmQnQ .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-PZHTfGFZYfoOmQnQ .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-PZHTfGFZYfoOmQnQ .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .section{stroke:none;opacity:0.2}#mermaid-svg-PZHTfGFZYfoOmQnQ .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-PZHTfGFZYfoOmQnQ .section2{fill:#fff400}#mermaid-svg-PZHTfGFZYfoOmQnQ .section1,#mermaid-svg-PZHTfGFZYfoOmQnQ .section3{fill:#fff;opacity:0.2}#mermaid-svg-PZHTfGFZYfoOmQnQ .sectionTitle0{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .sectionTitle1{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .sectionTitle2{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .sectionTitle3{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-PZHTfGFZYfoOmQnQ .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .grid path{stroke-width:0}#mermaid-svg-PZHTfGFZYfoOmQnQ .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-PZHTfGFZYfoOmQnQ .task{stroke-width:2}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText:not([font-size]){font-size:11px}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-PZHTfGFZYfoOmQnQ .task.clickable{cursor:pointer}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText0,#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText1,#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText2,#mermaid-svg-PZHTfGFZYfoOmQnQ .taskText3{fill:#fff}#mermaid-svg-PZHTfGFZYfoOmQnQ .task0,#mermaid-svg-PZHTfGFZYfoOmQnQ .task1,#mermaid-svg-PZHTfGFZYfoOmQnQ .task2,#mermaid-svg-PZHTfGFZYfoOmQnQ .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutside0,#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutside2{fill:#000}#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutside1,#mermaid-svg-PZHTfGFZYfoOmQnQ .taskTextOutside3{fill:#000}#mermaid-svg-PZHTfGFZYfoOmQnQ .active0,#mermaid-svg-PZHTfGFZYfoOmQnQ .active1,#mermaid-svg-PZHTfGFZYfoOmQnQ .active2,#mermaid-svg-PZHTfGFZYfoOmQnQ .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-PZHTfGFZYfoOmQnQ .activeText0,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeText1,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeText2,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeText3{fill:#000 !important}#mermaid-svg-PZHTfGFZYfoOmQnQ .done0,#mermaid-svg-PZHTfGFZYfoOmQnQ .done1,#mermaid-svg-PZHTfGFZYfoOmQnQ .done2,#mermaid-svg-PZHTfGFZYfoOmQnQ .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-PZHTfGFZYfoOmQnQ .doneText0,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneText1,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneText2,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneText3{fill:#000 !important}#mermaid-svg-PZHTfGFZYfoOmQnQ .crit0,#mermaid-svg-PZHTfGFZYfoOmQnQ .crit1,#mermaid-svg-PZHTfGFZYfoOmQnQ .crit2,#mermaid-svg-PZHTfGFZYfoOmQnQ .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCrit0,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCrit1,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCrit2,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCrit0,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCrit1,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCrit2,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-PZHTfGFZYfoOmQnQ .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-PZHTfGFZYfoOmQnQ .milestoneText{font-style:italic}#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCritText0,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCritText1,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCritText2,#mermaid-svg-PZHTfGFZYfoOmQnQ .doneCritText3{fill:#000 !important}#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCritText0,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCritText1,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCritText2,#mermaid-svg-PZHTfGFZYfoOmQnQ .activeCritText3{fill:#000 !important}#mermaid-svg-PZHTfGFZYfoOmQnQ .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-PZHTfGFZYfoOmQnQ g.classGroup text .title{font-weight:bolder}#mermaid-svg-PZHTfGFZYfoOmQnQ g.clickable{cursor:pointer}#mermaid-svg-PZHTfGFZYfoOmQnQ g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-PZHTfGFZYfoOmQnQ g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-PZHTfGFZYfoOmQnQ .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-PZHTfGFZYfoOmQnQ .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .dashed-line{stroke-dasharray:3}#mermaid-svg-PZHTfGFZYfoOmQnQ #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ .commit-id,#mermaid-svg-PZHTfGFZYfoOmQnQ .commit-msg,#mermaid-svg-PZHTfGFZYfoOmQnQ .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-PZHTfGFZYfoOmQnQ g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-PZHTfGFZYfoOmQnQ g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-PZHTfGFZYfoOmQnQ g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-PZHTfGFZYfoOmQnQ .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-PZHTfGFZYfoOmQnQ .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-PZHTfGFZYfoOmQnQ .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-PZHTfGFZYfoOmQnQ .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-PZHTfGFZYfoOmQnQ .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-PZHTfGFZYfoOmQnQ .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-PZHTfGFZYfoOmQnQ .edgeLabel text{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PZHTfGFZYfoOmQnQ .node circle.state-start{fill:black;stroke:black}#mermaid-svg-PZHTfGFZYfoOmQnQ .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-PZHTfGFZYfoOmQnQ #statediagram-barbEnd{fill:#9370db}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-state .divider{stroke:#9370db}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-PZHTfGFZYfoOmQnQ .note-edge{stroke-dasharray:5}#mermaid-svg-PZHTfGFZYfoOmQnQ .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-PZHTfGFZYfoOmQnQ .error-icon{fill:#522}#mermaid-svg-PZHTfGFZYfoOmQnQ .error-text{fill:#522;stroke:#522}#mermaid-svg-PZHTfGFZYfoOmQnQ .edge-thickness-normal{stroke-width:2px}#mermaid-svg-PZHTfGFZYfoOmQnQ .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-PZHTfGFZYfoOmQnQ .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-PZHTfGFZYfoOmQnQ .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-PZHTfGFZYfoOmQnQ .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-PZHTfGFZYfoOmQnQ .marker{fill:#333}#mermaid-svg-PZHTfGFZYfoOmQnQ .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-PZHTfGFZYfoOmQnQ {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
第一個結點
第二個結點
第三個結點
.....
最后一個結點
單鏈表的定義
我們可以很清晰的看到,每一項都會一個指標來指向下一項,但是我們也能發現,我們的最后一項好像沒有指,其實最后一項指標是指向了NULL,也就是我們的空, 結合上圖我們可以很清楚地看到,對于一個鏈表,它一共需要兩種型別地變數,一個資料項,一個指向下一項的指標,
下面展示一些 行內代碼片,
// 定義一個單鏈表 用typedef將struct list重命名為List,將List *命名為ListNode
typedef struct list{
int data;
struct list * next;
} List, * ListNode;
單鏈表的初始化
對于任何一個資料結構,我們對它的操作無非就是創建,銷毀,增刪改查這幾個最基本的操作,只有能掌握這幾個最基本的操作,我們才能擴展更多功能 對于一個單鏈表,其實也是可以分為兩種,一種是帶有頭結點 的,一種是不帶頭結點 的,這兩種的區別是什么呢?
<style>#mermaid-svg-Z5oGhugxgcxwJLpk .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .label text{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .node rect,#mermaid-svg-Z5oGhugxgcxwJLpk .node circle,#mermaid-svg-Z5oGhugxgcxwJLpk .node ellipse,#mermaid-svg-Z5oGhugxgcxwJLpk .node polygon,#mermaid-svg-Z5oGhugxgcxwJLpk .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Z5oGhugxgcxwJLpk .node .label{text-align:center;fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .node.clickable{cursor:pointer}#mermaid-svg-Z5oGhugxgcxwJLpk .arrowheadPath{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-Z5oGhugxgcxwJLpk .flowchart-link{stroke:#333;fill:none}#mermaid-svg-Z5oGhugxgcxwJLpk .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-Z5oGhugxgcxwJLpk .edgeLabel rect{opacity:0.9}#mermaid-svg-Z5oGhugxgcxwJLpk .edgeLabel span{color:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-Z5oGhugxgcxwJLpk .cluster text{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-Z5oGhugxgcxwJLpk .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Z5oGhugxgcxwJLpk text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-Z5oGhugxgcxwJLpk .actor-line{stroke:grey}#mermaid-svg-Z5oGhugxgcxwJLpk .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-Z5oGhugxgcxwJLpk #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .sequenceNumber{fill:#fff}#mermaid-svg-Z5oGhugxgcxwJLpk #sequencenumber{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk #crosshead path{fill:#333;stroke:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .messageText{fill:#333;stroke:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Z5oGhugxgcxwJLpk .labelText,#mermaid-svg-Z5oGhugxgcxwJLpk .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-Z5oGhugxgcxwJLpk .loopText,#mermaid-svg-Z5oGhugxgcxwJLpk .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-Z5oGhugxgcxwJLpk .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-Z5oGhugxgcxwJLpk .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Z5oGhugxgcxwJLpk .noteText,#mermaid-svg-Z5oGhugxgcxwJLpk .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-Z5oGhugxgcxwJLpk .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-Z5oGhugxgcxwJLpk .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-Z5oGhugxgcxwJLpk .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-Z5oGhugxgcxwJLpk .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .section{stroke:none;opacity:0.2}#mermaid-svg-Z5oGhugxgcxwJLpk .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-Z5oGhugxgcxwJLpk .section2{fill:#fff400}#mermaid-svg-Z5oGhugxgcxwJLpk .section1,#mermaid-svg-Z5oGhugxgcxwJLpk .section3{fill:#fff;opacity:0.2}#mermaid-svg-Z5oGhugxgcxwJLpk .sectionTitle0{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .sectionTitle1{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .sectionTitle2{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .sectionTitle3{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-Z5oGhugxgcxwJLpk .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .grid path{stroke-width:0}#mermaid-svg-Z5oGhugxgcxwJLpk .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-Z5oGhugxgcxwJLpk .task{stroke-width:2}#mermaid-svg-Z5oGhugxgcxwJLpk .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .taskText:not([font-size]){font-size:11px}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-Z5oGhugxgcxwJLpk .task.clickable{cursor:pointer}#mermaid-svg-Z5oGhugxgcxwJLpk .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Z5oGhugxgcxwJLpk .taskText0,#mermaid-svg-Z5oGhugxgcxwJLpk .taskText1,#mermaid-svg-Z5oGhugxgcxwJLpk .taskText2,#mermaid-svg-Z5oGhugxgcxwJLpk .taskText3{fill:#fff}#mermaid-svg-Z5oGhugxgcxwJLpk .task0,#mermaid-svg-Z5oGhugxgcxwJLpk .task1,#mermaid-svg-Z5oGhugxgcxwJLpk .task2,#mermaid-svg-Z5oGhugxgcxwJLpk .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutside0,#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutside2{fill:#000}#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutside1,#mermaid-svg-Z5oGhugxgcxwJLpk .taskTextOutside3{fill:#000}#mermaid-svg-Z5oGhugxgcxwJLpk .active0,#mermaid-svg-Z5oGhugxgcxwJLpk .active1,#mermaid-svg-Z5oGhugxgcxwJLpk .active2,#mermaid-svg-Z5oGhugxgcxwJLpk .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-Z5oGhugxgcxwJLpk .activeText0,#mermaid-svg-Z5oGhugxgcxwJLpk .activeText1,#mermaid-svg-Z5oGhugxgcxwJLpk .activeText2,#mermaid-svg-Z5oGhugxgcxwJLpk .activeText3{fill:#000 !important}#mermaid-svg-Z5oGhugxgcxwJLpk .done0,#mermaid-svg-Z5oGhugxgcxwJLpk .done1,#mermaid-svg-Z5oGhugxgcxwJLpk .done2,#mermaid-svg-Z5oGhugxgcxwJLpk .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-Z5oGhugxgcxwJLpk .doneText0,#mermaid-svg-Z5oGhugxgcxwJLpk .doneText1,#mermaid-svg-Z5oGhugxgcxwJLpk .doneText2,#mermaid-svg-Z5oGhugxgcxwJLpk .doneText3{fill:#000 !important}#mermaid-svg-Z5oGhugxgcxwJLpk .crit0,#mermaid-svg-Z5oGhugxgcxwJLpk .crit1,#mermaid-svg-Z5oGhugxgcxwJLpk .crit2,#mermaid-svg-Z5oGhugxgcxwJLpk .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-Z5oGhugxgcxwJLpk .activeCrit0,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCrit1,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCrit2,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-Z5oGhugxgcxwJLpk .doneCrit0,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCrit1,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCrit2,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-Z5oGhugxgcxwJLpk .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-Z5oGhugxgcxwJLpk .milestoneText{font-style:italic}#mermaid-svg-Z5oGhugxgcxwJLpk .doneCritText0,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCritText1,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCritText2,#mermaid-svg-Z5oGhugxgcxwJLpk .doneCritText3{fill:#000 !important}#mermaid-svg-Z5oGhugxgcxwJLpk .activeCritText0,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCritText1,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCritText2,#mermaid-svg-Z5oGhugxgcxwJLpk .activeCritText3{fill:#000 !important}#mermaid-svg-Z5oGhugxgcxwJLpk .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-Z5oGhugxgcxwJLpk g.classGroup text .title{font-weight:bolder}#mermaid-svg-Z5oGhugxgcxwJLpk g.clickable{cursor:pointer}#mermaid-svg-Z5oGhugxgcxwJLpk g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Z5oGhugxgcxwJLpk g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-Z5oGhugxgcxwJLpk .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-Z5oGhugxgcxwJLpk .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Z5oGhugxgcxwJLpk .dashed-line{stroke-dasharray:3}#mermaid-svg-Z5oGhugxgcxwJLpk #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk .commit-id,#mermaid-svg-Z5oGhugxgcxwJLpk .commit-msg,#mermaid-svg-Z5oGhugxgcxwJLpk .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-Z5oGhugxgcxwJLpk g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-Z5oGhugxgcxwJLpk g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Z5oGhugxgcxwJLpk g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Z5oGhugxgcxwJLpk .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Z5oGhugxgcxwJLpk .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-Z5oGhugxgcxwJLpk .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-Z5oGhugxgcxwJLpk .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Z5oGhugxgcxwJLpk .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-Z5oGhugxgcxwJLpk .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-Z5oGhugxgcxwJLpk .edgeLabel text{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Z5oGhugxgcxwJLpk .node circle.state-start{fill:black;stroke:black}#mermaid-svg-Z5oGhugxgcxwJLpk .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-Z5oGhugxgcxwJLpk #statediagram-barbEnd{fill:#9370db}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-state .divider{stroke:#9370db}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-Z5oGhugxgcxwJLpk .note-edge{stroke-dasharray:5}#mermaid-svg-Z5oGhugxgcxwJLpk .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-Z5oGhugxgcxwJLpk .error-icon{fill:#522}#mermaid-svg-Z5oGhugxgcxwJLpk .error-text{fill:#522;stroke:#522}#mermaid-svg-Z5oGhugxgcxwJLpk .edge-thickness-normal{stroke-width:2px}#mermaid-svg-Z5oGhugxgcxwJLpk .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-Z5oGhugxgcxwJLpk .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-Z5oGhugxgcxwJLpk .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-Z5oGhugxgcxwJLpk .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-Z5oGhugxgcxwJLpk .marker{fill:#333}#mermaid-svg-Z5oGhugxgcxwJLpk .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-Z5oGhugxgcxwJLpk {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
0
1
2
.....
n
這個例子就是個不帶頭結點 的 而下面這種就是帶頭結點的
<style>#mermaid-svg-7EjyCiVh1IUFOBaT .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .label text{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .node rect,#mermaid-svg-7EjyCiVh1IUFOBaT .node circle,#mermaid-svg-7EjyCiVh1IUFOBaT .node ellipse,#mermaid-svg-7EjyCiVh1IUFOBaT .node polygon,#mermaid-svg-7EjyCiVh1IUFOBaT .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-7EjyCiVh1IUFOBaT .node .label{text-align:center;fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .node.clickable{cursor:pointer}#mermaid-svg-7EjyCiVh1IUFOBaT .arrowheadPath{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-7EjyCiVh1IUFOBaT .flowchart-link{stroke:#333;fill:none}#mermaid-svg-7EjyCiVh1IUFOBaT .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-7EjyCiVh1IUFOBaT .edgeLabel rect{opacity:0.9}#mermaid-svg-7EjyCiVh1IUFOBaT .edgeLabel span{color:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-7EjyCiVh1IUFOBaT .cluster text{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-7EjyCiVh1IUFOBaT .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-7EjyCiVh1IUFOBaT text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-7EjyCiVh1IUFOBaT .actor-line{stroke:grey}#mermaid-svg-7EjyCiVh1IUFOBaT .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-7EjyCiVh1IUFOBaT #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .sequenceNumber{fill:#fff}#mermaid-svg-7EjyCiVh1IUFOBaT #sequencenumber{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT #crosshead path{fill:#333;stroke:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .messageText{fill:#333;stroke:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-7EjyCiVh1IUFOBaT .labelText,#mermaid-svg-7EjyCiVh1IUFOBaT .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-7EjyCiVh1IUFOBaT .loopText,#mermaid-svg-7EjyCiVh1IUFOBaT .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-7EjyCiVh1IUFOBaT .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-7EjyCiVh1IUFOBaT .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-7EjyCiVh1IUFOBaT .noteText,#mermaid-svg-7EjyCiVh1IUFOBaT .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-7EjyCiVh1IUFOBaT .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-7EjyCiVh1IUFOBaT .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-7EjyCiVh1IUFOBaT .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-7EjyCiVh1IUFOBaT .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .section{stroke:none;opacity:0.2}#mermaid-svg-7EjyCiVh1IUFOBaT .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-7EjyCiVh1IUFOBaT .section2{fill:#fff400}#mermaid-svg-7EjyCiVh1IUFOBaT .section1,#mermaid-svg-7EjyCiVh1IUFOBaT .section3{fill:#fff;opacity:0.2}#mermaid-svg-7EjyCiVh1IUFOBaT .sectionTitle0{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .sectionTitle1{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .sectionTitle2{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .sectionTitle3{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-7EjyCiVh1IUFOBaT .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .grid path{stroke-width:0}#mermaid-svg-7EjyCiVh1IUFOBaT .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-7EjyCiVh1IUFOBaT .task{stroke-width:2}#mermaid-svg-7EjyCiVh1IUFOBaT .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .taskText:not([font-size]){font-size:11px}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-7EjyCiVh1IUFOBaT .task.clickable{cursor:pointer}#mermaid-svg-7EjyCiVh1IUFOBaT .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-7EjyCiVh1IUFOBaT .taskText0,#mermaid-svg-7EjyCiVh1IUFOBaT .taskText1,#mermaid-svg-7EjyCiVh1IUFOBaT .taskText2,#mermaid-svg-7EjyCiVh1IUFOBaT .taskText3{fill:#fff}#mermaid-svg-7EjyCiVh1IUFOBaT .task0,#mermaid-svg-7EjyCiVh1IUFOBaT .task1,#mermaid-svg-7EjyCiVh1IUFOBaT .task2,#mermaid-svg-7EjyCiVh1IUFOBaT .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutside0,#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutside2{fill:#000}#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutside1,#mermaid-svg-7EjyCiVh1IUFOBaT .taskTextOutside3{fill:#000}#mermaid-svg-7EjyCiVh1IUFOBaT .active0,#mermaid-svg-7EjyCiVh1IUFOBaT .active1,#mermaid-svg-7EjyCiVh1IUFOBaT .active2,#mermaid-svg-7EjyCiVh1IUFOBaT .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-7EjyCiVh1IUFOBaT .activeText0,#mermaid-svg-7EjyCiVh1IUFOBaT .activeText1,#mermaid-svg-7EjyCiVh1IUFOBaT .activeText2,#mermaid-svg-7EjyCiVh1IUFOBaT .activeText3{fill:#000 !important}#mermaid-svg-7EjyCiVh1IUFOBaT .done0,#mermaid-svg-7EjyCiVh1IUFOBaT .done1,#mermaid-svg-7EjyCiVh1IUFOBaT .done2,#mermaid-svg-7EjyCiVh1IUFOBaT .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-7EjyCiVh1IUFOBaT .doneText0,#mermaid-svg-7EjyCiVh1IUFOBaT .doneText1,#mermaid-svg-7EjyCiVh1IUFOBaT .doneText2,#mermaid-svg-7EjyCiVh1IUFOBaT .doneText3{fill:#000 !important}#mermaid-svg-7EjyCiVh1IUFOBaT .crit0,#mermaid-svg-7EjyCiVh1IUFOBaT .crit1,#mermaid-svg-7EjyCiVh1IUFOBaT .crit2,#mermaid-svg-7EjyCiVh1IUFOBaT .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-7EjyCiVh1IUFOBaT .activeCrit0,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCrit1,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCrit2,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-7EjyCiVh1IUFOBaT .doneCrit0,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCrit1,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCrit2,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-7EjyCiVh1IUFOBaT .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-7EjyCiVh1IUFOBaT .milestoneText{font-style:italic}#mermaid-svg-7EjyCiVh1IUFOBaT .doneCritText0,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCritText1,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCritText2,#mermaid-svg-7EjyCiVh1IUFOBaT .doneCritText3{fill:#000 !important}#mermaid-svg-7EjyCiVh1IUFOBaT .activeCritText0,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCritText1,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCritText2,#mermaid-svg-7EjyCiVh1IUFOBaT .activeCritText3{fill:#000 !important}#mermaid-svg-7EjyCiVh1IUFOBaT .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-7EjyCiVh1IUFOBaT g.classGroup text .title{font-weight:bolder}#mermaid-svg-7EjyCiVh1IUFOBaT g.clickable{cursor:pointer}#mermaid-svg-7EjyCiVh1IUFOBaT g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-7EjyCiVh1IUFOBaT g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-7EjyCiVh1IUFOBaT .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-7EjyCiVh1IUFOBaT .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-7EjyCiVh1IUFOBaT .dashed-line{stroke-dasharray:3}#mermaid-svg-7EjyCiVh1IUFOBaT #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT .commit-id,#mermaid-svg-7EjyCiVh1IUFOBaT .commit-msg,#mermaid-svg-7EjyCiVh1IUFOBaT .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-7EjyCiVh1IUFOBaT g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-7EjyCiVh1IUFOBaT g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-7EjyCiVh1IUFOBaT g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-7EjyCiVh1IUFOBaT .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-7EjyCiVh1IUFOBaT .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-7EjyCiVh1IUFOBaT .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-7EjyCiVh1IUFOBaT .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-7EjyCiVh1IUFOBaT .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-7EjyCiVh1IUFOBaT .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-7EjyCiVh1IUFOBaT .edgeLabel text{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-7EjyCiVh1IUFOBaT .node circle.state-start{fill:black;stroke:black}#mermaid-svg-7EjyCiVh1IUFOBaT .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-7EjyCiVh1IUFOBaT #statediagram-barbEnd{fill:#9370db}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-state .divider{stroke:#9370db}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-7EjyCiVh1IUFOBaT .note-edge{stroke-dasharray:5}#mermaid-svg-7EjyCiVh1IUFOBaT .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-7EjyCiVh1IUFOBaT .error-icon{fill:#522}#mermaid-svg-7EjyCiVh1IUFOBaT .error-text{fill:#522;stroke:#522}#mermaid-svg-7EjyCiVh1IUFOBaT .edge-thickness-normal{stroke-width:2px}#mermaid-svg-7EjyCiVh1IUFOBaT .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-7EjyCiVh1IUFOBaT .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-7EjyCiVh1IUFOBaT .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-7EjyCiVh1IUFOBaT .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-7EjyCiVh1IUFOBaT .marker{fill:#333}#mermaid-svg-7EjyCiVh1IUFOBaT .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-7EjyCiVh1IUFOBaT {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
1
2
3
.....
n
我們可以清楚的感覺到,兩者最大的區別就在于帶頭結點的鏈表更符合人的計數方式,對于我們而言,更好維護和操作,并且能夠看出來,帶頭結點的單鏈表,他的頭結點是沒有data值的,因為我們并不需要它幫我們存取值,只是為了方便計數,所以他的data為預設型別,接下來我們來嘗試初始化一個單鏈表,這里我講的所有方法都是基于帶頭結點 的,有興趣的朋友們可以自己嘗試下不帶頭結點 該怎么定義
// 初始化一個單鏈表,因為有頭結點,所以頭結點的下一項才是真正的資料第1項
//為此我們就得給頭結點的指標所指的值來表示真實的第一項
void init ( ListNode & L)
{
//之所以用&是因為我們需要把處理之后的值回傳到我們的主函式里,而不是復制一個新的值僅僅在函式堆疊里處理
//引數我們傳入進來一個指標,指向的是一個List元素
L= ( List * ) malloc ( sizeof ( List) ) ; //在記憶體中申請一個空間存放頭結點
L- > next= NULL ;
//一個沒有任何元素的鏈表就初始化結束了
}
單鏈表的插入洗掉
對于單鏈表,我們要是想洗掉某一位上的元素,很明顯,第一步我們肯定是先找到這個位置的前一位,然后再將此位置前一位元素的next指標指向我們要插入的部分,而我們要插入的部分的next指標指向原本在這個位置的元素 比如我們在第三個位置插入P結點
<style>#mermaid-svg-Gh3hXERHMVKUwvJF .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .label text{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .node rect,#mermaid-svg-Gh3hXERHMVKUwvJF .node circle,#mermaid-svg-Gh3hXERHMVKUwvJF .node ellipse,#mermaid-svg-Gh3hXERHMVKUwvJF .node polygon,#mermaid-svg-Gh3hXERHMVKUwvJF .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Gh3hXERHMVKUwvJF .node .label{text-align:center;fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .node.clickable{cursor:pointer}#mermaid-svg-Gh3hXERHMVKUwvJF .arrowheadPath{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-Gh3hXERHMVKUwvJF .flowchart-link{stroke:#333;fill:none}#mermaid-svg-Gh3hXERHMVKUwvJF .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-Gh3hXERHMVKUwvJF .edgeLabel rect{opacity:0.9}#mermaid-svg-Gh3hXERHMVKUwvJF .edgeLabel span{color:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-Gh3hXERHMVKUwvJF .cluster text{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-Gh3hXERHMVKUwvJF .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Gh3hXERHMVKUwvJF text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-Gh3hXERHMVKUwvJF .actor-line{stroke:grey}#mermaid-svg-Gh3hXERHMVKUwvJF .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-Gh3hXERHMVKUwvJF #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .sequenceNumber{fill:#fff}#mermaid-svg-Gh3hXERHMVKUwvJF #sequencenumber{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF #crosshead path{fill:#333;stroke:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .messageText{fill:#333;stroke:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Gh3hXERHMVKUwvJF .labelText,#mermaid-svg-Gh3hXERHMVKUwvJF .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-Gh3hXERHMVKUwvJF .loopText,#mermaid-svg-Gh3hXERHMVKUwvJF .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-Gh3hXERHMVKUwvJF .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-Gh3hXERHMVKUwvJF .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Gh3hXERHMVKUwvJF .noteText,#mermaid-svg-Gh3hXERHMVKUwvJF .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-Gh3hXERHMVKUwvJF .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-Gh3hXERHMVKUwvJF .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-Gh3hXERHMVKUwvJF .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-Gh3hXERHMVKUwvJF .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .section{stroke:none;opacity:0.2}#mermaid-svg-Gh3hXERHMVKUwvJF .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-Gh3hXERHMVKUwvJF .section2{fill:#fff400}#mermaid-svg-Gh3hXERHMVKUwvJF .section1,#mermaid-svg-Gh3hXERHMVKUwvJF .section3{fill:#fff;opacity:0.2}#mermaid-svg-Gh3hXERHMVKUwvJF .sectionTitle0{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .sectionTitle1{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .sectionTitle2{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .sectionTitle3{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-Gh3hXERHMVKUwvJF .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .grid path{stroke-width:0}#mermaid-svg-Gh3hXERHMVKUwvJF .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-Gh3hXERHMVKUwvJF .task{stroke-width:2}#mermaid-svg-Gh3hXERHMVKUwvJF .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .taskText:not([font-size]){font-size:11px}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-Gh3hXERHMVKUwvJF .task.clickable{cursor:pointer}#mermaid-svg-Gh3hXERHMVKUwvJF .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Gh3hXERHMVKUwvJF .taskText0,#mermaid-svg-Gh3hXERHMVKUwvJF .taskText1,#mermaid-svg-Gh3hXERHMVKUwvJF .taskText2,#mermaid-svg-Gh3hXERHMVKUwvJF .taskText3{fill:#fff}#mermaid-svg-Gh3hXERHMVKUwvJF .task0,#mermaid-svg-Gh3hXERHMVKUwvJF .task1,#mermaid-svg-Gh3hXERHMVKUwvJF .task2,#mermaid-svg-Gh3hXERHMVKUwvJF .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutside0,#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutside2{fill:#000}#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutside1,#mermaid-svg-Gh3hXERHMVKUwvJF .taskTextOutside3{fill:#000}#mermaid-svg-Gh3hXERHMVKUwvJF .active0,#mermaid-svg-Gh3hXERHMVKUwvJF .active1,#mermaid-svg-Gh3hXERHMVKUwvJF .active2,#mermaid-svg-Gh3hXERHMVKUwvJF .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-Gh3hXERHMVKUwvJF .activeText0,#mermaid-svg-Gh3hXERHMVKUwvJF .activeText1,#mermaid-svg-Gh3hXERHMVKUwvJF .activeText2,#mermaid-svg-Gh3hXERHMVKUwvJF .activeText3{fill:#000 !important}#mermaid-svg-Gh3hXERHMVKUwvJF .done0,#mermaid-svg-Gh3hXERHMVKUwvJF .done1,#mermaid-svg-Gh3hXERHMVKUwvJF .done2,#mermaid-svg-Gh3hXERHMVKUwvJF .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-Gh3hXERHMVKUwvJF .doneText0,#mermaid-svg-Gh3hXERHMVKUwvJF .doneText1,#mermaid-svg-Gh3hXERHMVKUwvJF .doneText2,#mermaid-svg-Gh3hXERHMVKUwvJF .doneText3{fill:#000 !important}#mermaid-svg-Gh3hXERHMVKUwvJF .crit0,#mermaid-svg-Gh3hXERHMVKUwvJF .crit1,#mermaid-svg-Gh3hXERHMVKUwvJF .crit2,#mermaid-svg-Gh3hXERHMVKUwvJF .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-Gh3hXERHMVKUwvJF .activeCrit0,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCrit1,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCrit2,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-Gh3hXERHMVKUwvJF .doneCrit0,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCrit1,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCrit2,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-Gh3hXERHMVKUwvJF .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-Gh3hXERHMVKUwvJF .milestoneText{font-style:italic}#mermaid-svg-Gh3hXERHMVKUwvJF .doneCritText0,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCritText1,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCritText2,#mermaid-svg-Gh3hXERHMVKUwvJF .doneCritText3{fill:#000 !important}#mermaid-svg-Gh3hXERHMVKUwvJF .activeCritText0,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCritText1,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCritText2,#mermaid-svg-Gh3hXERHMVKUwvJF .activeCritText3{fill:#000 !important}#mermaid-svg-Gh3hXERHMVKUwvJF .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-Gh3hXERHMVKUwvJF g.classGroup text .title{font-weight:bolder}#mermaid-svg-Gh3hXERHMVKUwvJF g.clickable{cursor:pointer}#mermaid-svg-Gh3hXERHMVKUwvJF g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Gh3hXERHMVKUwvJF g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-Gh3hXERHMVKUwvJF .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-Gh3hXERHMVKUwvJF .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Gh3hXERHMVKUwvJF .dashed-line{stroke-dasharray:3}#mermaid-svg-Gh3hXERHMVKUwvJF #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF .commit-id,#mermaid-svg-Gh3hXERHMVKUwvJF .commit-msg,#mermaid-svg-Gh3hXERHMVKUwvJF .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-Gh3hXERHMVKUwvJF g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-Gh3hXERHMVKUwvJF g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Gh3hXERHMVKUwvJF g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Gh3hXERHMVKUwvJF .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Gh3hXERHMVKUwvJF .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-Gh3hXERHMVKUwvJF .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-Gh3hXERHMVKUwvJF .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Gh3hXERHMVKUwvJF .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-Gh3hXERHMVKUwvJF .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-Gh3hXERHMVKUwvJF .edgeLabel text{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Gh3hXERHMVKUwvJF .node circle.state-start{fill:black;stroke:black}#mermaid-svg-Gh3hXERHMVKUwvJF .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-Gh3hXERHMVKUwvJF #statediagram-barbEnd{fill:#9370db}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-state .divider{stroke:#9370db}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-Gh3hXERHMVKUwvJF .note-edge{stroke-dasharray:5}#mermaid-svg-Gh3hXERHMVKUwvJF .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-Gh3hXERHMVKUwvJF .error-icon{fill:#522}#mermaid-svg-Gh3hXERHMVKUwvJF .error-text{fill:#522;stroke:#522}#mermaid-svg-Gh3hXERHMVKUwvJF .edge-thickness-normal{stroke-width:2px}#mermaid-svg-Gh3hXERHMVKUwvJF .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-Gh3hXERHMVKUwvJF .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-Gh3hXERHMVKUwvJF .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-Gh3hXERHMVKUwvJF .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-Gh3hXERHMVKUwvJF .marker{fill:#333}#mermaid-svg-Gh3hXERHMVKUwvJF .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-Gh3hXERHMVKUwvJF {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
.....
n
p
然后我們先找到第二個位置b,找到之后我們把a->next指向p,p->next指向b
<style>#mermaid-svg-UHXbZRXp0ItTywEe .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-UHXbZRXp0ItTywEe .label text{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .node rect,#mermaid-svg-UHXbZRXp0ItTywEe .node circle,#mermaid-svg-UHXbZRXp0ItTywEe .node ellipse,#mermaid-svg-UHXbZRXp0ItTywEe .node polygon,#mermaid-svg-UHXbZRXp0ItTywEe .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-UHXbZRXp0ItTywEe .node .label{text-align:center;fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .node.clickable{cursor:pointer}#mermaid-svg-UHXbZRXp0ItTywEe .arrowheadPath{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-UHXbZRXp0ItTywEe .flowchart-link{stroke:#333;fill:none}#mermaid-svg-UHXbZRXp0ItTywEe .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-UHXbZRXp0ItTywEe .edgeLabel rect{opacity:0.9}#mermaid-svg-UHXbZRXp0ItTywEe .edgeLabel span{color:#333}#mermaid-svg-UHXbZRXp0ItTywEe .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-UHXbZRXp0ItTywEe .cluster text{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-UHXbZRXp0ItTywEe .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-UHXbZRXp0ItTywEe text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-UHXbZRXp0ItTywEe .actor-line{stroke:grey}#mermaid-svg-UHXbZRXp0ItTywEe .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-UHXbZRXp0ItTywEe .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-UHXbZRXp0ItTywEe #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-UHXbZRXp0ItTywEe .sequenceNumber{fill:#fff}#mermaid-svg-UHXbZRXp0ItTywEe #sequencenumber{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe #crosshead path{fill:#333;stroke:#333}#mermaid-svg-UHXbZRXp0ItTywEe .messageText{fill:#333;stroke:#333}#mermaid-svg-UHXbZRXp0ItTywEe .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-UHXbZRXp0ItTywEe .labelText,#mermaid-svg-UHXbZRXp0ItTywEe .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-UHXbZRXp0ItTywEe .loopText,#mermaid-svg-UHXbZRXp0ItTywEe .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-UHXbZRXp0ItTywEe .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-UHXbZRXp0ItTywEe .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-UHXbZRXp0ItTywEe .noteText,#mermaid-svg-UHXbZRXp0ItTywEe .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-UHXbZRXp0ItTywEe .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-UHXbZRXp0ItTywEe .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-UHXbZRXp0ItTywEe .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-UHXbZRXp0ItTywEe .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .section{stroke:none;opacity:0.2}#mermaid-svg-UHXbZRXp0ItTywEe .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-UHXbZRXp0ItTywEe .section2{fill:#fff400}#mermaid-svg-UHXbZRXp0ItTywEe .section1,#mermaid-svg-UHXbZRXp0ItTywEe .section3{fill:#fff;opacity:0.2}#mermaid-svg-UHXbZRXp0ItTywEe .sectionTitle0{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .sectionTitle1{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .sectionTitle2{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .sectionTitle3{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-UHXbZRXp0ItTywEe .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .grid path{stroke-width:0}#mermaid-svg-UHXbZRXp0ItTywEe .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-UHXbZRXp0ItTywEe .task{stroke-width:2}#mermaid-svg-UHXbZRXp0ItTywEe .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .taskText:not([font-size]){font-size:11px}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-UHXbZRXp0ItTywEe .task.clickable{cursor:pointer}#mermaid-svg-UHXbZRXp0ItTywEe .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-UHXbZRXp0ItTywEe .taskText0,#mermaid-svg-UHXbZRXp0ItTywEe .taskText1,#mermaid-svg-UHXbZRXp0ItTywEe .taskText2,#mermaid-svg-UHXbZRXp0ItTywEe .taskText3{fill:#fff}#mermaid-svg-UHXbZRXp0ItTywEe .task0,#mermaid-svg-UHXbZRXp0ItTywEe .task1,#mermaid-svg-UHXbZRXp0ItTywEe .task2,#mermaid-svg-UHXbZRXp0ItTywEe .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutside0,#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutside2{fill:#000}#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutside1,#mermaid-svg-UHXbZRXp0ItTywEe .taskTextOutside3{fill:#000}#mermaid-svg-UHXbZRXp0ItTywEe .active0,#mermaid-svg-UHXbZRXp0ItTywEe .active1,#mermaid-svg-UHXbZRXp0ItTywEe .active2,#mermaid-svg-UHXbZRXp0ItTywEe .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-UHXbZRXp0ItTywEe .activeText0,#mermaid-svg-UHXbZRXp0ItTywEe .activeText1,#mermaid-svg-UHXbZRXp0ItTywEe .activeText2,#mermaid-svg-UHXbZRXp0ItTywEe .activeText3{fill:#000 !important}#mermaid-svg-UHXbZRXp0ItTywEe .done0,#mermaid-svg-UHXbZRXp0ItTywEe .done1,#mermaid-svg-UHXbZRXp0ItTywEe .done2,#mermaid-svg-UHXbZRXp0ItTywEe .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-UHXbZRXp0ItTywEe .doneText0,#mermaid-svg-UHXbZRXp0ItTywEe .doneText1,#mermaid-svg-UHXbZRXp0ItTywEe .doneText2,#mermaid-svg-UHXbZRXp0ItTywEe .doneText3{fill:#000 !important}#mermaid-svg-UHXbZRXp0ItTywEe .crit0,#mermaid-svg-UHXbZRXp0ItTywEe .crit1,#mermaid-svg-UHXbZRXp0ItTywEe .crit2,#mermaid-svg-UHXbZRXp0ItTywEe .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-UHXbZRXp0ItTywEe .activeCrit0,#mermaid-svg-UHXbZRXp0ItTywEe .activeCrit1,#mermaid-svg-UHXbZRXp0ItTywEe .activeCrit2,#mermaid-svg-UHXbZRXp0ItTywEe .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-UHXbZRXp0ItTywEe .doneCrit0,#mermaid-svg-UHXbZRXp0ItTywEe .doneCrit1,#mermaid-svg-UHXbZRXp0ItTywEe .doneCrit2,#mermaid-svg-UHXbZRXp0ItTywEe .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-UHXbZRXp0ItTywEe .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-UHXbZRXp0ItTywEe .milestoneText{font-style:italic}#mermaid-svg-UHXbZRXp0ItTywEe .doneCritText0,#mermaid-svg-UHXbZRXp0ItTywEe .doneCritText1,#mermaid-svg-UHXbZRXp0ItTywEe .doneCritText2,#mermaid-svg-UHXbZRXp0ItTywEe .doneCritText3{fill:#000 !important}#mermaid-svg-UHXbZRXp0ItTywEe .activeCritText0,#mermaid-svg-UHXbZRXp0ItTywEe .activeCritText1,#mermaid-svg-UHXbZRXp0ItTywEe .activeCritText2,#mermaid-svg-UHXbZRXp0ItTywEe .activeCritText3{fill:#000 !important}#mermaid-svg-UHXbZRXp0ItTywEe .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-UHXbZRXp0ItTywEe g.classGroup text .title{font-weight:bolder}#mermaid-svg-UHXbZRXp0ItTywEe g.clickable{cursor:pointer}#mermaid-svg-UHXbZRXp0ItTywEe g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-UHXbZRXp0ItTywEe g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-UHXbZRXp0ItTywEe .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-UHXbZRXp0ItTywEe .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-UHXbZRXp0ItTywEe .dashed-line{stroke-dasharray:3}#mermaid-svg-UHXbZRXp0ItTywEe #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe .commit-id,#mermaid-svg-UHXbZRXp0ItTywEe .commit-msg,#mermaid-svg-UHXbZRXp0ItTywEe .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-UHXbZRXp0ItTywEe g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-UHXbZRXp0ItTywEe g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-UHXbZRXp0ItTywEe g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-UHXbZRXp0ItTywEe .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-UHXbZRXp0ItTywEe .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-UHXbZRXp0ItTywEe .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-UHXbZRXp0ItTywEe .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-UHXbZRXp0ItTywEe .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-UHXbZRXp0ItTywEe .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-UHXbZRXp0ItTywEe .edgeLabel text{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-UHXbZRXp0ItTywEe .node circle.state-start{fill:black;stroke:black}#mermaid-svg-UHXbZRXp0ItTywEe .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-UHXbZRXp0ItTywEe #statediagram-barbEnd{fill:#9370db}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-state .divider{stroke:#9370db}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-UHXbZRXp0ItTywEe .note-edge{stroke-dasharray:5}#mermaid-svg-UHXbZRXp0ItTywEe .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-UHXbZRXp0ItTywEe .error-icon{fill:#522}#mermaid-svg-UHXbZRXp0ItTywEe .error-text{fill:#522;stroke:#522}#mermaid-svg-UHXbZRXp0ItTywEe .edge-thickness-normal{stroke-width:2px}#mermaid-svg-UHXbZRXp0ItTywEe .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-UHXbZRXp0ItTywEe .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-UHXbZRXp0ItTywEe .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-UHXbZRXp0ItTywEe .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-UHXbZRXp0ItTywEe .marker{fill:#333}#mermaid-svg-UHXbZRXp0ItTywEe .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-UHXbZRXp0ItTywEe {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
.....
n
p
<style>#mermaid-svg-zzdGCuiab6u65mad .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-zzdGCuiab6u65mad .label text{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .node rect,#mermaid-svg-zzdGCuiab6u65mad .node circle,#mermaid-svg-zzdGCuiab6u65mad .node ellipse,#mermaid-svg-zzdGCuiab6u65mad .node polygon,#mermaid-svg-zzdGCuiab6u65mad .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-zzdGCuiab6u65mad .node .label{text-align:center;fill:#333}#mermaid-svg-zzdGCuiab6u65mad .node.clickable{cursor:pointer}#mermaid-svg-zzdGCuiab6u65mad .arrowheadPath{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-zzdGCuiab6u65mad .flowchart-link{stroke:#333;fill:none}#mermaid-svg-zzdGCuiab6u65mad .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-zzdGCuiab6u65mad .edgeLabel rect{opacity:0.9}#mermaid-svg-zzdGCuiab6u65mad .edgeLabel span{color:#333}#mermaid-svg-zzdGCuiab6u65mad .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-zzdGCuiab6u65mad .cluster text{fill:#333}#mermaid-svg-zzdGCuiab6u65mad div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-zzdGCuiab6u65mad .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-zzdGCuiab6u65mad text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-zzdGCuiab6u65mad .actor-line{stroke:grey}#mermaid-svg-zzdGCuiab6u65mad .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-zzdGCuiab6u65mad .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-zzdGCuiab6u65mad #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-zzdGCuiab6u65mad .sequenceNumber{fill:#fff}#mermaid-svg-zzdGCuiab6u65mad #sequencenumber{fill:#333}#mermaid-svg-zzdGCuiab6u65mad #crosshead path{fill:#333;stroke:#333}#mermaid-svg-zzdGCuiab6u65mad .messageText{fill:#333;stroke:#333}#mermaid-svg-zzdGCuiab6u65mad .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-zzdGCuiab6u65mad .labelText,#mermaid-svg-zzdGCuiab6u65mad .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-zzdGCuiab6u65mad .loopText,#mermaid-svg-zzdGCuiab6u65mad .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-zzdGCuiab6u65mad .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-zzdGCuiab6u65mad .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-zzdGCuiab6u65mad .noteText,#mermaid-svg-zzdGCuiab6u65mad .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-zzdGCuiab6u65mad .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-zzdGCuiab6u65mad .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-zzdGCuiab6u65mad .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-zzdGCuiab6u65mad .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .section{stroke:none;opacity:0.2}#mermaid-svg-zzdGCuiab6u65mad .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-zzdGCuiab6u65mad .section2{fill:#fff400}#mermaid-svg-zzdGCuiab6u65mad .section1,#mermaid-svg-zzdGCuiab6u65mad .section3{fill:#fff;opacity:0.2}#mermaid-svg-zzdGCuiab6u65mad .sectionTitle0{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .sectionTitle1{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .sectionTitle2{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .sectionTitle3{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-zzdGCuiab6u65mad .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .grid path{stroke-width:0}#mermaid-svg-zzdGCuiab6u65mad .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-zzdGCuiab6u65mad .task{stroke-width:2}#mermaid-svg-zzdGCuiab6u65mad .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .taskText:not([font-size]){font-size:11px}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-zzdGCuiab6u65mad .task.clickable{cursor:pointer}#mermaid-svg-zzdGCuiab6u65mad .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-zzdGCuiab6u65mad .taskText0,#mermaid-svg-zzdGCuiab6u65mad .taskText1,#mermaid-svg-zzdGCuiab6u65mad .taskText2,#mermaid-svg-zzdGCuiab6u65mad .taskText3{fill:#fff}#mermaid-svg-zzdGCuiab6u65mad .task0,#mermaid-svg-zzdGCuiab6u65mad .task1,#mermaid-svg-zzdGCuiab6u65mad .task2,#mermaid-svg-zzdGCuiab6u65mad .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutside0,#mermaid-svg-zzdGCuiab6u65mad .taskTextOutside2{fill:#000}#mermaid-svg-zzdGCuiab6u65mad .taskTextOutside1,#mermaid-svg-zzdGCuiab6u65mad .taskTextOutside3{fill:#000}#mermaid-svg-zzdGCuiab6u65mad .active0,#mermaid-svg-zzdGCuiab6u65mad .active1,#mermaid-svg-zzdGCuiab6u65mad .active2,#mermaid-svg-zzdGCuiab6u65mad .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-zzdGCuiab6u65mad .activeText0,#mermaid-svg-zzdGCuiab6u65mad .activeText1,#mermaid-svg-zzdGCuiab6u65mad .activeText2,#mermaid-svg-zzdGCuiab6u65mad .activeText3{fill:#000 !important}#mermaid-svg-zzdGCuiab6u65mad .done0,#mermaid-svg-zzdGCuiab6u65mad .done1,#mermaid-svg-zzdGCuiab6u65mad .done2,#mermaid-svg-zzdGCuiab6u65mad .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-zzdGCuiab6u65mad .doneText0,#mermaid-svg-zzdGCuiab6u65mad .doneText1,#mermaid-svg-zzdGCuiab6u65mad .doneText2,#mermaid-svg-zzdGCuiab6u65mad .doneText3{fill:#000 !important}#mermaid-svg-zzdGCuiab6u65mad .crit0,#mermaid-svg-zzdGCuiab6u65mad .crit1,#mermaid-svg-zzdGCuiab6u65mad .crit2,#mermaid-svg-zzdGCuiab6u65mad .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-zzdGCuiab6u65mad .activeCrit0,#mermaid-svg-zzdGCuiab6u65mad .activeCrit1,#mermaid-svg-zzdGCuiab6u65mad .activeCrit2,#mermaid-svg-zzdGCuiab6u65mad .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-zzdGCuiab6u65mad .doneCrit0,#mermaid-svg-zzdGCuiab6u65mad .doneCrit1,#mermaid-svg-zzdGCuiab6u65mad .doneCrit2,#mermaid-svg-zzdGCuiab6u65mad .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-zzdGCuiab6u65mad .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-zzdGCuiab6u65mad .milestoneText{font-style:italic}#mermaid-svg-zzdGCuiab6u65mad .doneCritText0,#mermaid-svg-zzdGCuiab6u65mad .doneCritText1,#mermaid-svg-zzdGCuiab6u65mad .doneCritText2,#mermaid-svg-zzdGCuiab6u65mad .doneCritText3{fill:#000 !important}#mermaid-svg-zzdGCuiab6u65mad .activeCritText0,#mermaid-svg-zzdGCuiab6u65mad .activeCritText1,#mermaid-svg-zzdGCuiab6u65mad .activeCritText2,#mermaid-svg-zzdGCuiab6u65mad .activeCritText3{fill:#000 !important}#mermaid-svg-zzdGCuiab6u65mad .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-zzdGCuiab6u65mad g.classGroup text .title{font-weight:bolder}#mermaid-svg-zzdGCuiab6u65mad g.clickable{cursor:pointer}#mermaid-svg-zzdGCuiab6u65mad g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-zzdGCuiab6u65mad g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-zzdGCuiab6u65mad .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-zzdGCuiab6u65mad .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-zzdGCuiab6u65mad .dashed-line{stroke-dasharray:3}#mermaid-svg-zzdGCuiab6u65mad #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad .commit-id,#mermaid-svg-zzdGCuiab6u65mad .commit-msg,#mermaid-svg-zzdGCuiab6u65mad .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-zzdGCuiab6u65mad g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-zzdGCuiab6u65mad g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-zzdGCuiab6u65mad g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-zzdGCuiab6u65mad g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-zzdGCuiab6u65mad .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-zzdGCuiab6u65mad .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-zzdGCuiab6u65mad .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-zzdGCuiab6u65mad .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-zzdGCuiab6u65mad .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-zzdGCuiab6u65mad .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-zzdGCuiab6u65mad .edgeLabel text{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-zzdGCuiab6u65mad .node circle.state-start{fill:black;stroke:black}#mermaid-svg-zzdGCuiab6u65mad .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-zzdGCuiab6u65mad #statediagram-barbEnd{fill:#9370db}#mermaid-svg-zzdGCuiab6u65mad .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-zzdGCuiab6u65mad .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-zzdGCuiab6u65mad .statediagram-state .divider{stroke:#9370db}#mermaid-svg-zzdGCuiab6u65mad .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-zzdGCuiab6u65mad .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-zzdGCuiab6u65mad .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-zzdGCuiab6u65mad .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-zzdGCuiab6u65mad .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-zzdGCuiab6u65mad .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-zzdGCuiab6u65mad .note-edge{stroke-dasharray:5}#mermaid-svg-zzdGCuiab6u65mad .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-zzdGCuiab6u65mad .error-icon{fill:#522}#mermaid-svg-zzdGCuiab6u65mad .error-text{fill:#522;stroke:#522}#mermaid-svg-zzdGCuiab6u65mad .edge-thickness-normal{stroke-width:2px}#mermaid-svg-zzdGCuiab6u65mad .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-zzdGCuiab6u65mad .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-zzdGCuiab6u65mad .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-zzdGCuiab6u65mad .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-zzdGCuiab6u65mad .marker{fill:#333}#mermaid-svg-zzdGCuiab6u65mad .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-zzdGCuiab6u65mad {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
.....
n
p
用代碼實作時,我們把其封裝到一個insert函式里面,這里我們應該看出來,我們應該有三個引數,分別是List * &L一個鏈表,int n,第n個位置,int e 需要插入的元素
// 一定要判斷插入位置是否正確
bool insert ( List * & L, int n, int e)
{
if ( n< 1 ) //檢測位置是否合法
return false ;
List * p= L;
int j= 0
while ( p!= NULL && j< n- 1 ) //找到插入元素之前的位置
{
p= p- > next;
j++ ;
}
if ( p== NULL )
return false ; //確認插入有無超出鏈表范圍
List * s= ( List * )malloc ( sizeof ( List) ) ; //存放新元素的data
s- > data= e;
s- > next= p- > next;
p- > next= s;
return true ;
}
單鏈表的洗掉
其實洗掉的原理和增加也很想,第一步就是找到要洗掉的位置的前一位p,然后讓p直接指向p->next->next即可,然后清理記憶體中的p就行了 比如洗掉第三位的c
<style>#mermaid-svg-YrQIqdms7RUzTzLu .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-YrQIqdms7RUzTzLu .label text{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .node rect,#mermaid-svg-YrQIqdms7RUzTzLu .node circle,#mermaid-svg-YrQIqdms7RUzTzLu .node ellipse,#mermaid-svg-YrQIqdms7RUzTzLu .node polygon,#mermaid-svg-YrQIqdms7RUzTzLu .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-YrQIqdms7RUzTzLu .node .label{text-align:center;fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .node.clickable{cursor:pointer}#mermaid-svg-YrQIqdms7RUzTzLu .arrowheadPath{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-YrQIqdms7RUzTzLu .flowchart-link{stroke:#333;fill:none}#mermaid-svg-YrQIqdms7RUzTzLu .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-YrQIqdms7RUzTzLu .edgeLabel rect{opacity:0.9}#mermaid-svg-YrQIqdms7RUzTzLu .edgeLabel span{color:#333}#mermaid-svg-YrQIqdms7RUzTzLu .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-YrQIqdms7RUzTzLu .cluster text{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-YrQIqdms7RUzTzLu .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-YrQIqdms7RUzTzLu text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-YrQIqdms7RUzTzLu .actor-line{stroke:grey}#mermaid-svg-YrQIqdms7RUzTzLu .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-YrQIqdms7RUzTzLu .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-YrQIqdms7RUzTzLu #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-YrQIqdms7RUzTzLu .sequenceNumber{fill:#fff}#mermaid-svg-YrQIqdms7RUzTzLu #sequencenumber{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu #crosshead path{fill:#333;stroke:#333}#mermaid-svg-YrQIqdms7RUzTzLu .messageText{fill:#333;stroke:#333}#mermaid-svg-YrQIqdms7RUzTzLu .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-YrQIqdms7RUzTzLu .labelText,#mermaid-svg-YrQIqdms7RUzTzLu .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-YrQIqdms7RUzTzLu .loopText,#mermaid-svg-YrQIqdms7RUzTzLu .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-YrQIqdms7RUzTzLu .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-YrQIqdms7RUzTzLu .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-YrQIqdms7RUzTzLu .noteText,#mermaid-svg-YrQIqdms7RUzTzLu .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-YrQIqdms7RUzTzLu .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-YrQIqdms7RUzTzLu .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-YrQIqdms7RUzTzLu .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-YrQIqdms7RUzTzLu .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .section{stroke:none;opacity:0.2}#mermaid-svg-YrQIqdms7RUzTzLu .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-YrQIqdms7RUzTzLu .section2{fill:#fff400}#mermaid-svg-YrQIqdms7RUzTzLu .section1,#mermaid-svg-YrQIqdms7RUzTzLu .section3{fill:#fff;opacity:0.2}#mermaid-svg-YrQIqdms7RUzTzLu .sectionTitle0{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .sectionTitle1{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .sectionTitle2{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .sectionTitle3{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-YrQIqdms7RUzTzLu .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .grid path{stroke-width:0}#mermaid-svg-YrQIqdms7RUzTzLu .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-YrQIqdms7RUzTzLu .task{stroke-width:2}#mermaid-svg-YrQIqdms7RUzTzLu .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .taskText:not([font-size]){font-size:11px}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-YrQIqdms7RUzTzLu .task.clickable{cursor:pointer}#mermaid-svg-YrQIqdms7RUzTzLu .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-YrQIqdms7RUzTzLu .taskText0,#mermaid-svg-YrQIqdms7RUzTzLu .taskText1,#mermaid-svg-YrQIqdms7RUzTzLu .taskText2,#mermaid-svg-YrQIqdms7RUzTzLu .taskText3{fill:#fff}#mermaid-svg-YrQIqdms7RUzTzLu .task0,#mermaid-svg-YrQIqdms7RUzTzLu .task1,#mermaid-svg-YrQIqdms7RUzTzLu .task2,#mermaid-svg-YrQIqdms7RUzTzLu .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutside0,#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutside2{fill:#000}#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutside1,#mermaid-svg-YrQIqdms7RUzTzLu .taskTextOutside3{fill:#000}#mermaid-svg-YrQIqdms7RUzTzLu .active0,#mermaid-svg-YrQIqdms7RUzTzLu .active1,#mermaid-svg-YrQIqdms7RUzTzLu .active2,#mermaid-svg-YrQIqdms7RUzTzLu .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-YrQIqdms7RUzTzLu .activeText0,#mermaid-svg-YrQIqdms7RUzTzLu .activeText1,#mermaid-svg-YrQIqdms7RUzTzLu .activeText2,#mermaid-svg-YrQIqdms7RUzTzLu .activeText3{fill:#000 !important}#mermaid-svg-YrQIqdms7RUzTzLu .done0,#mermaid-svg-YrQIqdms7RUzTzLu .done1,#mermaid-svg-YrQIqdms7RUzTzLu .done2,#mermaid-svg-YrQIqdms7RUzTzLu .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-YrQIqdms7RUzTzLu .doneText0,#mermaid-svg-YrQIqdms7RUzTzLu .doneText1,#mermaid-svg-YrQIqdms7RUzTzLu .doneText2,#mermaid-svg-YrQIqdms7RUzTzLu .doneText3{fill:#000 !important}#mermaid-svg-YrQIqdms7RUzTzLu .crit0,#mermaid-svg-YrQIqdms7RUzTzLu .crit1,#mermaid-svg-YrQIqdms7RUzTzLu .crit2,#mermaid-svg-YrQIqdms7RUzTzLu .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-YrQIqdms7RUzTzLu .activeCrit0,#mermaid-svg-YrQIqdms7RUzTzLu .activeCrit1,#mermaid-svg-YrQIqdms7RUzTzLu .activeCrit2,#mermaid-svg-YrQIqdms7RUzTzLu .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-YrQIqdms7RUzTzLu .doneCrit0,#mermaid-svg-YrQIqdms7RUzTzLu .doneCrit1,#mermaid-svg-YrQIqdms7RUzTzLu .doneCrit2,#mermaid-svg-YrQIqdms7RUzTzLu .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-YrQIqdms7RUzTzLu .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-YrQIqdms7RUzTzLu .milestoneText{font-style:italic}#mermaid-svg-YrQIqdms7RUzTzLu .doneCritText0,#mermaid-svg-YrQIqdms7RUzTzLu .doneCritText1,#mermaid-svg-YrQIqdms7RUzTzLu .doneCritText2,#mermaid-svg-YrQIqdms7RUzTzLu .doneCritText3{fill:#000 !important}#mermaid-svg-YrQIqdms7RUzTzLu .activeCritText0,#mermaid-svg-YrQIqdms7RUzTzLu .activeCritText1,#mermaid-svg-YrQIqdms7RUzTzLu .activeCritText2,#mermaid-svg-YrQIqdms7RUzTzLu .activeCritText3{fill:#000 !important}#mermaid-svg-YrQIqdms7RUzTzLu .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-YrQIqdms7RUzTzLu g.classGroup text .title{font-weight:bolder}#mermaid-svg-YrQIqdms7RUzTzLu g.clickable{cursor:pointer}#mermaid-svg-YrQIqdms7RUzTzLu g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-YrQIqdms7RUzTzLu g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-YrQIqdms7RUzTzLu .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-YrQIqdms7RUzTzLu .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-YrQIqdms7RUzTzLu .dashed-line{stroke-dasharray:3}#mermaid-svg-YrQIqdms7RUzTzLu #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu .commit-id,#mermaid-svg-YrQIqdms7RUzTzLu .commit-msg,#mermaid-svg-YrQIqdms7RUzTzLu .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-YrQIqdms7RUzTzLu g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-YrQIqdms7RUzTzLu g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-YrQIqdms7RUzTzLu g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-YrQIqdms7RUzTzLu .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-YrQIqdms7RUzTzLu .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-YrQIqdms7RUzTzLu .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-YrQIqdms7RUzTzLu .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-YrQIqdms7RUzTzLu .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-YrQIqdms7RUzTzLu .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-YrQIqdms7RUzTzLu .edgeLabel text{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-YrQIqdms7RUzTzLu .node circle.state-start{fill:black;stroke:black}#mermaid-svg-YrQIqdms7RUzTzLu .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-YrQIqdms7RUzTzLu #statediagram-barbEnd{fill:#9370db}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-state .divider{stroke:#9370db}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-YrQIqdms7RUzTzLu .note-edge{stroke-dasharray:5}#mermaid-svg-YrQIqdms7RUzTzLu .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-YrQIqdms7RUzTzLu .error-icon{fill:#522}#mermaid-svg-YrQIqdms7RUzTzLu .error-text{fill:#522;stroke:#522}#mermaid-svg-YrQIqdms7RUzTzLu .edge-thickness-normal{stroke-width:2px}#mermaid-svg-YrQIqdms7RUzTzLu .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-YrQIqdms7RUzTzLu .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-YrQIqdms7RUzTzLu .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-YrQIqdms7RUzTzLu .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-YrQIqdms7RUzTzLu .marker{fill:#333}#mermaid-svg-YrQIqdms7RUzTzLu .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-YrQIqdms7RUzTzLu {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
.....
n
<style>#mermaid-svg-ouH26fs5Ep7mWkYw .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .label text{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .node rect,#mermaid-svg-ouH26fs5Ep7mWkYw .node circle,#mermaid-svg-ouH26fs5Ep7mWkYw .node ellipse,#mermaid-svg-ouH26fs5Ep7mWkYw .node polygon,#mermaid-svg-ouH26fs5Ep7mWkYw .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-ouH26fs5Ep7mWkYw .node .label{text-align:center;fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .node.clickable{cursor:pointer}#mermaid-svg-ouH26fs5Ep7mWkYw .arrowheadPath{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-ouH26fs5Ep7mWkYw .flowchart-link{stroke:#333;fill:none}#mermaid-svg-ouH26fs5Ep7mWkYw .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-ouH26fs5Ep7mWkYw .edgeLabel rect{opacity:0.9}#mermaid-svg-ouH26fs5Ep7mWkYw .edgeLabel span{color:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-ouH26fs5Ep7mWkYw .cluster text{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-ouH26fs5Ep7mWkYw .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-ouH26fs5Ep7mWkYw text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-ouH26fs5Ep7mWkYw .actor-line{stroke:grey}#mermaid-svg-ouH26fs5Ep7mWkYw .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-ouH26fs5Ep7mWkYw #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .sequenceNumber{fill:#fff}#mermaid-svg-ouH26fs5Ep7mWkYw #sequencenumber{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw #crosshead path{fill:#333;stroke:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .messageText{fill:#333;stroke:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-ouH26fs5Ep7mWkYw .labelText,#mermaid-svg-ouH26fs5Ep7mWkYw .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-ouH26fs5Ep7mWkYw .loopText,#mermaid-svg-ouH26fs5Ep7mWkYw .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-ouH26fs5Ep7mWkYw .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-ouH26fs5Ep7mWkYw .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-ouH26fs5Ep7mWkYw .noteText,#mermaid-svg-ouH26fs5Ep7mWkYw .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-ouH26fs5Ep7mWkYw .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-ouH26fs5Ep7mWkYw .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-ouH26fs5Ep7mWkYw .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-ouH26fs5Ep7mWkYw .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .section{stroke:none;opacity:0.2}#mermaid-svg-ouH26fs5Ep7mWkYw .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-ouH26fs5Ep7mWkYw .section2{fill:#fff400}#mermaid-svg-ouH26fs5Ep7mWkYw .section1,#mermaid-svg-ouH26fs5Ep7mWkYw .section3{fill:#fff;opacity:0.2}#mermaid-svg-ouH26fs5Ep7mWkYw .sectionTitle0{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .sectionTitle1{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .sectionTitle2{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .sectionTitle3{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-ouH26fs5Ep7mWkYw .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .grid path{stroke-width:0}#mermaid-svg-ouH26fs5Ep7mWkYw .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-ouH26fs5Ep7mWkYw .task{stroke-width:2}#mermaid-svg-ouH26fs5Ep7mWkYw .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .taskText:not([font-size]){font-size:11px}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-ouH26fs5Ep7mWkYw .task.clickable{cursor:pointer}#mermaid-svg-ouH26fs5Ep7mWkYw .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-ouH26fs5Ep7mWkYw .taskText0,#mermaid-svg-ouH26fs5Ep7mWkYw .taskText1,#mermaid-svg-ouH26fs5Ep7mWkYw .taskText2,#mermaid-svg-ouH26fs5Ep7mWkYw .taskText3{fill:#fff}#mermaid-svg-ouH26fs5Ep7mWkYw .task0,#mermaid-svg-ouH26fs5Ep7mWkYw .task1,#mermaid-svg-ouH26fs5Ep7mWkYw .task2,#mermaid-svg-ouH26fs5Ep7mWkYw .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutside0,#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutside2{fill:#000}#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutside1,#mermaid-svg-ouH26fs5Ep7mWkYw .taskTextOutside3{fill:#000}#mermaid-svg-ouH26fs5Ep7mWkYw .active0,#mermaid-svg-ouH26fs5Ep7mWkYw .active1,#mermaid-svg-ouH26fs5Ep7mWkYw .active2,#mermaid-svg-ouH26fs5Ep7mWkYw .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-ouH26fs5Ep7mWkYw .activeText0,#mermaid-svg-ouH26fs5Ep7mWkYw .activeText1,#mermaid-svg-ouH26fs5Ep7mWkYw .activeText2,#mermaid-svg-ouH26fs5Ep7mWkYw .activeText3{fill:#000 !important}#mermaid-svg-ouH26fs5Ep7mWkYw .done0,#mermaid-svg-ouH26fs5Ep7mWkYw .done1,#mermaid-svg-ouH26fs5Ep7mWkYw .done2,#mermaid-svg-ouH26fs5Ep7mWkYw .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-ouH26fs5Ep7mWkYw .doneText0,#mermaid-svg-ouH26fs5Ep7mWkYw .doneText1,#mermaid-svg-ouH26fs5Ep7mWkYw .doneText2,#mermaid-svg-ouH26fs5Ep7mWkYw .doneText3{fill:#000 !important}#mermaid-svg-ouH26fs5Ep7mWkYw .crit0,#mermaid-svg-ouH26fs5Ep7mWkYw .crit1,#mermaid-svg-ouH26fs5Ep7mWkYw .crit2,#mermaid-svg-ouH26fs5Ep7mWkYw .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-ouH26fs5Ep7mWkYw .activeCrit0,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCrit1,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCrit2,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-ouH26fs5Ep7mWkYw .doneCrit0,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCrit1,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCrit2,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-ouH26fs5Ep7mWkYw .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-ouH26fs5Ep7mWkYw .milestoneText{font-style:italic}#mermaid-svg-ouH26fs5Ep7mWkYw .doneCritText0,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCritText1,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCritText2,#mermaid-svg-ouH26fs5Ep7mWkYw .doneCritText3{fill:#000 !important}#mermaid-svg-ouH26fs5Ep7mWkYw .activeCritText0,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCritText1,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCritText2,#mermaid-svg-ouH26fs5Ep7mWkYw .activeCritText3{fill:#000 !important}#mermaid-svg-ouH26fs5Ep7mWkYw .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-ouH26fs5Ep7mWkYw g.classGroup text .title{font-weight:bolder}#mermaid-svg-ouH26fs5Ep7mWkYw g.clickable{cursor:pointer}#mermaid-svg-ouH26fs5Ep7mWkYw g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-ouH26fs5Ep7mWkYw g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-ouH26fs5Ep7mWkYw .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-ouH26fs5Ep7mWkYw .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-ouH26fs5Ep7mWkYw .dashed-line{stroke-dasharray:3}#mermaid-svg-ouH26fs5Ep7mWkYw #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw .commit-id,#mermaid-svg-ouH26fs5Ep7mWkYw .commit-msg,#mermaid-svg-ouH26fs5Ep7mWkYw .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-ouH26fs5Ep7mWkYw g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-ouH26fs5Ep7mWkYw g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-ouH26fs5Ep7mWkYw g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-ouH26fs5Ep7mWkYw .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-ouH26fs5Ep7mWkYw .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-ouH26fs5Ep7mWkYw .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-ouH26fs5Ep7mWkYw .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-ouH26fs5Ep7mWkYw .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-ouH26fs5Ep7mWkYw .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-ouH26fs5Ep7mWkYw .edgeLabel text{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-ouH26fs5Ep7mWkYw .node circle.state-start{fill:black;stroke:black}#mermaid-svg-ouH26fs5Ep7mWkYw .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-ouH26fs5Ep7mWkYw #statediagram-barbEnd{fill:#9370db}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-state .divider{stroke:#9370db}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-ouH26fs5Ep7mWkYw .note-edge{stroke-dasharray:5}#mermaid-svg-ouH26fs5Ep7mWkYw .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-ouH26fs5Ep7mWkYw .error-icon{fill:#522}#mermaid-svg-ouH26fs5Ep7mWkYw .error-text{fill:#522;stroke:#522}#mermaid-svg-ouH26fs5Ep7mWkYw .edge-thickness-normal{stroke-width:2px}#mermaid-svg-ouH26fs5Ep7mWkYw .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-ouH26fs5Ep7mWkYw .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-ouH26fs5Ep7mWkYw .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-ouH26fs5Ep7mWkYw .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-ouH26fs5Ep7mWkYw .marker{fill:#333}#mermaid-svg-ouH26fs5Ep7mWkYw .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-ouH26fs5Ep7mWkYw {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
c
b
.....
n
bool remove ( List * & L, int n)
{
if ( n< 1 ) //檢測位置是否合法
return false ;
List * p= L;
int j= 0
while ( p!= NULL && j< n- 1 ) //找到洗掉元素之前的位置
{
p= p- > next;
j++ ;
}
if ( p== NULL )
return false ; //確認插入有無超出鏈表范圍
List * q= p- > next;
p- > next= q- > next;
free ( q) ;
return true ;
}
單鏈表的查找
寫到這里,估計有好多細心的朋友們發現了,我們之前的一大串尋找第n-1個位置和插入操作基本沒變,變的只是后面的邏輯上的操作,所以,我們可以在用一個方法把之前那一大塊封裝起來,以方便我們維護
List * getNode ( List * & L, int n)
{
if ( n< 1 ) //檢測位置是否合法
return NULL ;
List * p= L;
int j= 0
while ( p!= NULL && j< n) //找到元素的位置
{
p= p- > next;
j++ ;
}
return p; //如果p是NULL,他也會回傳NULL
]
單鏈表的修改
其實只要能寫出來查找,修改只不過是在查找的基礎上,把data項修改了而已
void changeNode ( List * & L, int n, int e)
{
List * p= getNode ( List * & L, int n) ; //直接呼叫我們寫好的查找函式
if ( p!= NULL )
p- > data= e;
]
單鏈表的建立
單鏈表的建立分為兩種模式,一種是頭插法 ,一種是尾插法 頭插法
<style>#mermaid-svg-pGILDh4Evpc5WG4a .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-pGILDh4Evpc5WG4a .label text{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .node rect,#mermaid-svg-pGILDh4Evpc5WG4a .node circle,#mermaid-svg-pGILDh4Evpc5WG4a .node ellipse,#mermaid-svg-pGILDh4Evpc5WG4a .node polygon,#mermaid-svg-pGILDh4Evpc5WG4a .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-pGILDh4Evpc5WG4a .node .label{text-align:center;fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .node.clickable{cursor:pointer}#mermaid-svg-pGILDh4Evpc5WG4a .arrowheadPath{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-pGILDh4Evpc5WG4a .flowchart-link{stroke:#333;fill:none}#mermaid-svg-pGILDh4Evpc5WG4a .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-pGILDh4Evpc5WG4a .edgeLabel rect{opacity:0.9}#mermaid-svg-pGILDh4Evpc5WG4a .edgeLabel span{color:#333}#mermaid-svg-pGILDh4Evpc5WG4a .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-pGILDh4Evpc5WG4a .cluster text{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-pGILDh4Evpc5WG4a .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-pGILDh4Evpc5WG4a text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-pGILDh4Evpc5WG4a .actor-line{stroke:grey}#mermaid-svg-pGILDh4Evpc5WG4a .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-pGILDh4Evpc5WG4a .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-pGILDh4Evpc5WG4a #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-pGILDh4Evpc5WG4a .sequenceNumber{fill:#fff}#mermaid-svg-pGILDh4Evpc5WG4a #sequencenumber{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a #crosshead path{fill:#333;stroke:#333}#mermaid-svg-pGILDh4Evpc5WG4a .messageText{fill:#333;stroke:#333}#mermaid-svg-pGILDh4Evpc5WG4a .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-pGILDh4Evpc5WG4a .labelText,#mermaid-svg-pGILDh4Evpc5WG4a .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-pGILDh4Evpc5WG4a .loopText,#mermaid-svg-pGILDh4Evpc5WG4a .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-pGILDh4Evpc5WG4a .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-pGILDh4Evpc5WG4a .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-pGILDh4Evpc5WG4a .noteText,#mermaid-svg-pGILDh4Evpc5WG4a .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-pGILDh4Evpc5WG4a .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-pGILDh4Evpc5WG4a .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-pGILDh4Evpc5WG4a .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-pGILDh4Evpc5WG4a .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .section{stroke:none;opacity:0.2}#mermaid-svg-pGILDh4Evpc5WG4a .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-pGILDh4Evpc5WG4a .section2{fill:#fff400}#mermaid-svg-pGILDh4Evpc5WG4a .section1,#mermaid-svg-pGILDh4Evpc5WG4a .section3{fill:#fff;opacity:0.2}#mermaid-svg-pGILDh4Evpc5WG4a .sectionTitle0{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .sectionTitle1{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .sectionTitle2{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .sectionTitle3{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-pGILDh4Evpc5WG4a .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .grid path{stroke-width:0}#mermaid-svg-pGILDh4Evpc5WG4a .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-pGILDh4Evpc5WG4a .task{stroke-width:2}#mermaid-svg-pGILDh4Evpc5WG4a .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .taskText:not([font-size]){font-size:11px}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-pGILDh4Evpc5WG4a .task.clickable{cursor:pointer}#mermaid-svg-pGILDh4Evpc5WG4a .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-pGILDh4Evpc5WG4a .taskText0,#mermaid-svg-pGILDh4Evpc5WG4a .taskText1,#mermaid-svg-pGILDh4Evpc5WG4a .taskText2,#mermaid-svg-pGILDh4Evpc5WG4a .taskText3{fill:#fff}#mermaid-svg-pGILDh4Evpc5WG4a .task0,#mermaid-svg-pGILDh4Evpc5WG4a .task1,#mermaid-svg-pGILDh4Evpc5WG4a .task2,#mermaid-svg-pGILDh4Evpc5WG4a .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutside0,#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutside2{fill:#000}#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutside1,#mermaid-svg-pGILDh4Evpc5WG4a .taskTextOutside3{fill:#000}#mermaid-svg-pGILDh4Evpc5WG4a .active0,#mermaid-svg-pGILDh4Evpc5WG4a .active1,#mermaid-svg-pGILDh4Evpc5WG4a .active2,#mermaid-svg-pGILDh4Evpc5WG4a .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-pGILDh4Evpc5WG4a .activeText0,#mermaid-svg-pGILDh4Evpc5WG4a .activeText1,#mermaid-svg-pGILDh4Evpc5WG4a .activeText2,#mermaid-svg-pGILDh4Evpc5WG4a .activeText3{fill:#000 !important}#mermaid-svg-pGILDh4Evpc5WG4a .done0,#mermaid-svg-pGILDh4Evpc5WG4a .done1,#mermaid-svg-pGILDh4Evpc5WG4a .done2,#mermaid-svg-pGILDh4Evpc5WG4a .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-pGILDh4Evpc5WG4a .doneText0,#mermaid-svg-pGILDh4Evpc5WG4a .doneText1,#mermaid-svg-pGILDh4Evpc5WG4a .doneText2,#mermaid-svg-pGILDh4Evpc5WG4a .doneText3{fill:#000 !important}#mermaid-svg-pGILDh4Evpc5WG4a .crit0,#mermaid-svg-pGILDh4Evpc5WG4a .crit1,#mermaid-svg-pGILDh4Evpc5WG4a .crit2,#mermaid-svg-pGILDh4Evpc5WG4a .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-pGILDh4Evpc5WG4a .activeCrit0,#mermaid-svg-pGILDh4Evpc5WG4a .activeCrit1,#mermaid-svg-pGILDh4Evpc5WG4a .activeCrit2,#mermaid-svg-pGILDh4Evpc5WG4a .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-pGILDh4Evpc5WG4a .doneCrit0,#mermaid-svg-pGILDh4Evpc5WG4a .doneCrit1,#mermaid-svg-pGILDh4Evpc5WG4a .doneCrit2,#mermaid-svg-pGILDh4Evpc5WG4a .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-pGILDh4Evpc5WG4a .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-pGILDh4Evpc5WG4a .milestoneText{font-style:italic}#mermaid-svg-pGILDh4Evpc5WG4a .doneCritText0,#mermaid-svg-pGILDh4Evpc5WG4a .doneCritText1,#mermaid-svg-pGILDh4Evpc5WG4a .doneCritText2,#mermaid-svg-pGILDh4Evpc5WG4a .doneCritText3{fill:#000 !important}#mermaid-svg-pGILDh4Evpc5WG4a .activeCritText0,#mermaid-svg-pGILDh4Evpc5WG4a .activeCritText1,#mermaid-svg-pGILDh4Evpc5WG4a .activeCritText2,#mermaid-svg-pGILDh4Evpc5WG4a .activeCritText3{fill:#000 !important}#mermaid-svg-pGILDh4Evpc5WG4a .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-pGILDh4Evpc5WG4a g.classGroup text .title{font-weight:bolder}#mermaid-svg-pGILDh4Evpc5WG4a g.clickable{cursor:pointer}#mermaid-svg-pGILDh4Evpc5WG4a g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-pGILDh4Evpc5WG4a g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-pGILDh4Evpc5WG4a .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-pGILDh4Evpc5WG4a .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-pGILDh4Evpc5WG4a .dashed-line{stroke-dasharray:3}#mermaid-svg-pGILDh4Evpc5WG4a #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a .commit-id,#mermaid-svg-pGILDh4Evpc5WG4a .commit-msg,#mermaid-svg-pGILDh4Evpc5WG4a .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-pGILDh4Evpc5WG4a g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-pGILDh4Evpc5WG4a g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-pGILDh4Evpc5WG4a g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-pGILDh4Evpc5WG4a .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-pGILDh4Evpc5WG4a .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-pGILDh4Evpc5WG4a .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-pGILDh4Evpc5WG4a .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-pGILDh4Evpc5WG4a .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-pGILDh4Evpc5WG4a .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-pGILDh4Evpc5WG4a .edgeLabel text{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-pGILDh4Evpc5WG4a .node circle.state-start{fill:black;stroke:black}#mermaid-svg-pGILDh4Evpc5WG4a .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-pGILDh4Evpc5WG4a #statediagram-barbEnd{fill:#9370db}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-state .divider{stroke:#9370db}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-pGILDh4Evpc5WG4a .note-edge{stroke-dasharray:5}#mermaid-svg-pGILDh4Evpc5WG4a .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-pGILDh4Evpc5WG4a .error-icon{fill:#522}#mermaid-svg-pGILDh4Evpc5WG4a .error-text{fill:#522;stroke:#522}#mermaid-svg-pGILDh4Evpc5WG4a .edge-thickness-normal{stroke-width:2px}#mermaid-svg-pGILDh4Evpc5WG4a .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-pGILDh4Evpc5WG4a .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-pGILDh4Evpc5WG4a .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-pGILDh4Evpc5WG4a .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-pGILDh4Evpc5WG4a .marker{fill:#333}#mermaid-svg-pGILDh4Evpc5WG4a .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-pGILDh4Evpc5WG4a {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
p
比如我們要往這個鏈表中加入新的元素p,頭插法的做法是每次就加入到頭結點的后面
<style>#mermaid-svg-GpdS1T9i8n31icIC .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-GpdS1T9i8n31icIC .label text{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .node rect,#mermaid-svg-GpdS1T9i8n31icIC .node circle,#mermaid-svg-GpdS1T9i8n31icIC .node ellipse,#mermaid-svg-GpdS1T9i8n31icIC .node polygon,#mermaid-svg-GpdS1T9i8n31icIC .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-GpdS1T9i8n31icIC .node .label{text-align:center;fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .node.clickable{cursor:pointer}#mermaid-svg-GpdS1T9i8n31icIC .arrowheadPath{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-GpdS1T9i8n31icIC .flowchart-link{stroke:#333;fill:none}#mermaid-svg-GpdS1T9i8n31icIC .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-GpdS1T9i8n31icIC .edgeLabel rect{opacity:0.9}#mermaid-svg-GpdS1T9i8n31icIC .edgeLabel span{color:#333}#mermaid-svg-GpdS1T9i8n31icIC .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-GpdS1T9i8n31icIC .cluster text{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-GpdS1T9i8n31icIC .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-GpdS1T9i8n31icIC text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-GpdS1T9i8n31icIC .actor-line{stroke:grey}#mermaid-svg-GpdS1T9i8n31icIC .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-GpdS1T9i8n31icIC .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-GpdS1T9i8n31icIC #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-GpdS1T9i8n31icIC .sequenceNumber{fill:#fff}#mermaid-svg-GpdS1T9i8n31icIC #sequencenumber{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC #crosshead path{fill:#333;stroke:#333}#mermaid-svg-GpdS1T9i8n31icIC .messageText{fill:#333;stroke:#333}#mermaid-svg-GpdS1T9i8n31icIC .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-GpdS1T9i8n31icIC .labelText,#mermaid-svg-GpdS1T9i8n31icIC .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-GpdS1T9i8n31icIC .loopText,#mermaid-svg-GpdS1T9i8n31icIC .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-GpdS1T9i8n31icIC .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-GpdS1T9i8n31icIC .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-GpdS1T9i8n31icIC .noteText,#mermaid-svg-GpdS1T9i8n31icIC .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-GpdS1T9i8n31icIC .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-GpdS1T9i8n31icIC .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-GpdS1T9i8n31icIC .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-GpdS1T9i8n31icIC .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .section{stroke:none;opacity:0.2}#mermaid-svg-GpdS1T9i8n31icIC .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-GpdS1T9i8n31icIC .section2{fill:#fff400}#mermaid-svg-GpdS1T9i8n31icIC .section1,#mermaid-svg-GpdS1T9i8n31icIC .section3{fill:#fff;opacity:0.2}#mermaid-svg-GpdS1T9i8n31icIC .sectionTitle0{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .sectionTitle1{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .sectionTitle2{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .sectionTitle3{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-GpdS1T9i8n31icIC .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .grid path{stroke-width:0}#mermaid-svg-GpdS1T9i8n31icIC .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-GpdS1T9i8n31icIC .task{stroke-width:2}#mermaid-svg-GpdS1T9i8n31icIC .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .taskText:not([font-size]){font-size:11px}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-GpdS1T9i8n31icIC .task.clickable{cursor:pointer}#mermaid-svg-GpdS1T9i8n31icIC .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-GpdS1T9i8n31icIC .taskText0,#mermaid-svg-GpdS1T9i8n31icIC .taskText1,#mermaid-svg-GpdS1T9i8n31icIC .taskText2,#mermaid-svg-GpdS1T9i8n31icIC .taskText3{fill:#fff}#mermaid-svg-GpdS1T9i8n31icIC .task0,#mermaid-svg-GpdS1T9i8n31icIC .task1,#mermaid-svg-GpdS1T9i8n31icIC .task2,#mermaid-svg-GpdS1T9i8n31icIC .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutside0,#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutside2{fill:#000}#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutside1,#mermaid-svg-GpdS1T9i8n31icIC .taskTextOutside3{fill:#000}#mermaid-svg-GpdS1T9i8n31icIC .active0,#mermaid-svg-GpdS1T9i8n31icIC .active1,#mermaid-svg-GpdS1T9i8n31icIC .active2,#mermaid-svg-GpdS1T9i8n31icIC .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-GpdS1T9i8n31icIC .activeText0,#mermaid-svg-GpdS1T9i8n31icIC .activeText1,#mermaid-svg-GpdS1T9i8n31icIC .activeText2,#mermaid-svg-GpdS1T9i8n31icIC .activeText3{fill:#000 !important}#mermaid-svg-GpdS1T9i8n31icIC .done0,#mermaid-svg-GpdS1T9i8n31icIC .done1,#mermaid-svg-GpdS1T9i8n31icIC .done2,#mermaid-svg-GpdS1T9i8n31icIC .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-GpdS1T9i8n31icIC .doneText0,#mermaid-svg-GpdS1T9i8n31icIC .doneText1,#mermaid-svg-GpdS1T9i8n31icIC .doneText2,#mermaid-svg-GpdS1T9i8n31icIC .doneText3{fill:#000 !important}#mermaid-svg-GpdS1T9i8n31icIC .crit0,#mermaid-svg-GpdS1T9i8n31icIC .crit1,#mermaid-svg-GpdS1T9i8n31icIC .crit2,#mermaid-svg-GpdS1T9i8n31icIC .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-GpdS1T9i8n31icIC .activeCrit0,#mermaid-svg-GpdS1T9i8n31icIC .activeCrit1,#mermaid-svg-GpdS1T9i8n31icIC .activeCrit2,#mermaid-svg-GpdS1T9i8n31icIC .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-GpdS1T9i8n31icIC .doneCrit0,#mermaid-svg-GpdS1T9i8n31icIC .doneCrit1,#mermaid-svg-GpdS1T9i8n31icIC .doneCrit2,#mermaid-svg-GpdS1T9i8n31icIC .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-GpdS1T9i8n31icIC .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-GpdS1T9i8n31icIC .milestoneText{font-style:italic}#mermaid-svg-GpdS1T9i8n31icIC .doneCritText0,#mermaid-svg-GpdS1T9i8n31icIC .doneCritText1,#mermaid-svg-GpdS1T9i8n31icIC .doneCritText2,#mermaid-svg-GpdS1T9i8n31icIC .doneCritText3{fill:#000 !important}#mermaid-svg-GpdS1T9i8n31icIC .activeCritText0,#mermaid-svg-GpdS1T9i8n31icIC .activeCritText1,#mermaid-svg-GpdS1T9i8n31icIC .activeCritText2,#mermaid-svg-GpdS1T9i8n31icIC .activeCritText3{fill:#000 !important}#mermaid-svg-GpdS1T9i8n31icIC .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-GpdS1T9i8n31icIC g.classGroup text .title{font-weight:bolder}#mermaid-svg-GpdS1T9i8n31icIC g.clickable{cursor:pointer}#mermaid-svg-GpdS1T9i8n31icIC g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-GpdS1T9i8n31icIC g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-GpdS1T9i8n31icIC .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-GpdS1T9i8n31icIC .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-GpdS1T9i8n31icIC .dashed-line{stroke-dasharray:3}#mermaid-svg-GpdS1T9i8n31icIC #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC .commit-id,#mermaid-svg-GpdS1T9i8n31icIC .commit-msg,#mermaid-svg-GpdS1T9i8n31icIC .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-GpdS1T9i8n31icIC g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-GpdS1T9i8n31icIC g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-GpdS1T9i8n31icIC g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-GpdS1T9i8n31icIC .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-GpdS1T9i8n31icIC .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-GpdS1T9i8n31icIC .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-GpdS1T9i8n31icIC .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-GpdS1T9i8n31icIC .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-GpdS1T9i8n31icIC .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-GpdS1T9i8n31icIC .edgeLabel text{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-GpdS1T9i8n31icIC .node circle.state-start{fill:black;stroke:black}#mermaid-svg-GpdS1T9i8n31icIC .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-GpdS1T9i8n31icIC #statediagram-barbEnd{fill:#9370db}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-state .divider{stroke:#9370db}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-GpdS1T9i8n31icIC .note-edge{stroke-dasharray:5}#mermaid-svg-GpdS1T9i8n31icIC .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-GpdS1T9i8n31icIC .error-icon{fill:#522}#mermaid-svg-GpdS1T9i8n31icIC .error-text{fill:#522;stroke:#522}#mermaid-svg-GpdS1T9i8n31icIC .edge-thickness-normal{stroke-width:2px}#mermaid-svg-GpdS1T9i8n31icIC .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-GpdS1T9i8n31icIC .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-GpdS1T9i8n31icIC .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-GpdS1T9i8n31icIC .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-GpdS1T9i8n31icIC .marker{fill:#333}#mermaid-svg-GpdS1T9i8n31icIC .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-GpdS1T9i8n31icIC {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
p
a
b
c
尾插法
<style>#mermaid-svg-fexjVGlrhPqaABrI .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-fexjVGlrhPqaABrI .label text{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .node rect,#mermaid-svg-fexjVGlrhPqaABrI .node circle,#mermaid-svg-fexjVGlrhPqaABrI .node ellipse,#mermaid-svg-fexjVGlrhPqaABrI .node polygon,#mermaid-svg-fexjVGlrhPqaABrI .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-fexjVGlrhPqaABrI .node .label{text-align:center;fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .node.clickable{cursor:pointer}#mermaid-svg-fexjVGlrhPqaABrI .arrowheadPath{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-fexjVGlrhPqaABrI .flowchart-link{stroke:#333;fill:none}#mermaid-svg-fexjVGlrhPqaABrI .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-fexjVGlrhPqaABrI .edgeLabel rect{opacity:0.9}#mermaid-svg-fexjVGlrhPqaABrI .edgeLabel span{color:#333}#mermaid-svg-fexjVGlrhPqaABrI .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-fexjVGlrhPqaABrI .cluster text{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-fexjVGlrhPqaABrI .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-fexjVGlrhPqaABrI text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-fexjVGlrhPqaABrI .actor-line{stroke:grey}#mermaid-svg-fexjVGlrhPqaABrI .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-fexjVGlrhPqaABrI .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-fexjVGlrhPqaABrI #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-fexjVGlrhPqaABrI .sequenceNumber{fill:#fff}#mermaid-svg-fexjVGlrhPqaABrI #sequencenumber{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI #crosshead path{fill:#333;stroke:#333}#mermaid-svg-fexjVGlrhPqaABrI .messageText{fill:#333;stroke:#333}#mermaid-svg-fexjVGlrhPqaABrI .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-fexjVGlrhPqaABrI .labelText,#mermaid-svg-fexjVGlrhPqaABrI .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-fexjVGlrhPqaABrI .loopText,#mermaid-svg-fexjVGlrhPqaABrI .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-fexjVGlrhPqaABrI .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-fexjVGlrhPqaABrI .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-fexjVGlrhPqaABrI .noteText,#mermaid-svg-fexjVGlrhPqaABrI .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-fexjVGlrhPqaABrI .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-fexjVGlrhPqaABrI .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-fexjVGlrhPqaABrI .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-fexjVGlrhPqaABrI .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .section{stroke:none;opacity:0.2}#mermaid-svg-fexjVGlrhPqaABrI .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-fexjVGlrhPqaABrI .section2{fill:#fff400}#mermaid-svg-fexjVGlrhPqaABrI .section1,#mermaid-svg-fexjVGlrhPqaABrI .section3{fill:#fff;opacity:0.2}#mermaid-svg-fexjVGlrhPqaABrI .sectionTitle0{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .sectionTitle1{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .sectionTitle2{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .sectionTitle3{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-fexjVGlrhPqaABrI .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .grid path{stroke-width:0}#mermaid-svg-fexjVGlrhPqaABrI .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-fexjVGlrhPqaABrI .task{stroke-width:2}#mermaid-svg-fexjVGlrhPqaABrI .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .taskText:not([font-size]){font-size:11px}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-fexjVGlrhPqaABrI .task.clickable{cursor:pointer}#mermaid-svg-fexjVGlrhPqaABrI .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-fexjVGlrhPqaABrI .taskText0,#mermaid-svg-fexjVGlrhPqaABrI .taskText1,#mermaid-svg-fexjVGlrhPqaABrI .taskText2,#mermaid-svg-fexjVGlrhPqaABrI .taskText3{fill:#fff}#mermaid-svg-fexjVGlrhPqaABrI .task0,#mermaid-svg-fexjVGlrhPqaABrI .task1,#mermaid-svg-fexjVGlrhPqaABrI .task2,#mermaid-svg-fexjVGlrhPqaABrI .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutside0,#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutside2{fill:#000}#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutside1,#mermaid-svg-fexjVGlrhPqaABrI .taskTextOutside3{fill:#000}#mermaid-svg-fexjVGlrhPqaABrI .active0,#mermaid-svg-fexjVGlrhPqaABrI .active1,#mermaid-svg-fexjVGlrhPqaABrI .active2,#mermaid-svg-fexjVGlrhPqaABrI .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-fexjVGlrhPqaABrI .activeText0,#mermaid-svg-fexjVGlrhPqaABrI .activeText1,#mermaid-svg-fexjVGlrhPqaABrI .activeText2,#mermaid-svg-fexjVGlrhPqaABrI .activeText3{fill:#000 !important}#mermaid-svg-fexjVGlrhPqaABrI .done0,#mermaid-svg-fexjVGlrhPqaABrI .done1,#mermaid-svg-fexjVGlrhPqaABrI .done2,#mermaid-svg-fexjVGlrhPqaABrI .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-fexjVGlrhPqaABrI .doneText0,#mermaid-svg-fexjVGlrhPqaABrI .doneText1,#mermaid-svg-fexjVGlrhPqaABrI .doneText2,#mermaid-svg-fexjVGlrhPqaABrI .doneText3{fill:#000 !important}#mermaid-svg-fexjVGlrhPqaABrI .crit0,#mermaid-svg-fexjVGlrhPqaABrI .crit1,#mermaid-svg-fexjVGlrhPqaABrI .crit2,#mermaid-svg-fexjVGlrhPqaABrI .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-fexjVGlrhPqaABrI .activeCrit0,#mermaid-svg-fexjVGlrhPqaABrI .activeCrit1,#mermaid-svg-fexjVGlrhPqaABrI .activeCrit2,#mermaid-svg-fexjVGlrhPqaABrI .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-fexjVGlrhPqaABrI .doneCrit0,#mermaid-svg-fexjVGlrhPqaABrI .doneCrit1,#mermaid-svg-fexjVGlrhPqaABrI .doneCrit2,#mermaid-svg-fexjVGlrhPqaABrI .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-fexjVGlrhPqaABrI .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-fexjVGlrhPqaABrI .milestoneText{font-style:italic}#mermaid-svg-fexjVGlrhPqaABrI .doneCritText0,#mermaid-svg-fexjVGlrhPqaABrI .doneCritText1,#mermaid-svg-fexjVGlrhPqaABrI .doneCritText2,#mermaid-svg-fexjVGlrhPqaABrI .doneCritText3{fill:#000 !important}#mermaid-svg-fexjVGlrhPqaABrI .activeCritText0,#mermaid-svg-fexjVGlrhPqaABrI .activeCritText1,#mermaid-svg-fexjVGlrhPqaABrI .activeCritText2,#mermaid-svg-fexjVGlrhPqaABrI .activeCritText3{fill:#000 !important}#mermaid-svg-fexjVGlrhPqaABrI .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-fexjVGlrhPqaABrI g.classGroup text .title{font-weight:bolder}#mermaid-svg-fexjVGlrhPqaABrI g.clickable{cursor:pointer}#mermaid-svg-fexjVGlrhPqaABrI g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-fexjVGlrhPqaABrI g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-fexjVGlrhPqaABrI .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-fexjVGlrhPqaABrI .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-fexjVGlrhPqaABrI .dashed-line{stroke-dasharray:3}#mermaid-svg-fexjVGlrhPqaABrI #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI .commit-id,#mermaid-svg-fexjVGlrhPqaABrI .commit-msg,#mermaid-svg-fexjVGlrhPqaABrI .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-fexjVGlrhPqaABrI g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-fexjVGlrhPqaABrI g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-fexjVGlrhPqaABrI g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-fexjVGlrhPqaABrI .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-fexjVGlrhPqaABrI .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-fexjVGlrhPqaABrI .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-fexjVGlrhPqaABrI .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-fexjVGlrhPqaABrI .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-fexjVGlrhPqaABrI .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-fexjVGlrhPqaABrI .edgeLabel text{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-fexjVGlrhPqaABrI .node circle.state-start{fill:black;stroke:black}#mermaid-svg-fexjVGlrhPqaABrI .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-fexjVGlrhPqaABrI #statediagram-barbEnd{fill:#9370db}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-state .divider{stroke:#9370db}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-fexjVGlrhPqaABrI .note-edge{stroke-dasharray:5}#mermaid-svg-fexjVGlrhPqaABrI .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-fexjVGlrhPqaABrI .error-icon{fill:#522}#mermaid-svg-fexjVGlrhPqaABrI .error-text{fill:#522;stroke:#522}#mermaid-svg-fexjVGlrhPqaABrI .edge-thickness-normal{stroke-width:2px}#mermaid-svg-fexjVGlrhPqaABrI .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-fexjVGlrhPqaABrI .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-fexjVGlrhPqaABrI .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-fexjVGlrhPqaABrI .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-fexjVGlrhPqaABrI .marker{fill:#333}#mermaid-svg-fexjVGlrhPqaABrI .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-fexjVGlrhPqaABrI {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
p
比如我們要往這個鏈表中加入新的元素p,尾插法的做法是每次就加入到最后一個結點的后面
<style>#mermaid-svg-1gA5YT1NwANi2tQs .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-1gA5YT1NwANi2tQs .label text{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .node rect,#mermaid-svg-1gA5YT1NwANi2tQs .node circle,#mermaid-svg-1gA5YT1NwANi2tQs .node ellipse,#mermaid-svg-1gA5YT1NwANi2tQs .node polygon,#mermaid-svg-1gA5YT1NwANi2tQs .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-1gA5YT1NwANi2tQs .node .label{text-align:center;fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .node.clickable{cursor:pointer}#mermaid-svg-1gA5YT1NwANi2tQs .arrowheadPath{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-1gA5YT1NwANi2tQs .flowchart-link{stroke:#333;fill:none}#mermaid-svg-1gA5YT1NwANi2tQs .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-1gA5YT1NwANi2tQs .edgeLabel rect{opacity:0.9}#mermaid-svg-1gA5YT1NwANi2tQs .edgeLabel span{color:#333}#mermaid-svg-1gA5YT1NwANi2tQs .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-1gA5YT1NwANi2tQs .cluster text{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-1gA5YT1NwANi2tQs .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-1gA5YT1NwANi2tQs text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-1gA5YT1NwANi2tQs .actor-line{stroke:grey}#mermaid-svg-1gA5YT1NwANi2tQs .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-1gA5YT1NwANi2tQs .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-1gA5YT1NwANi2tQs #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-1gA5YT1NwANi2tQs .sequenceNumber{fill:#fff}#mermaid-svg-1gA5YT1NwANi2tQs #sequencenumber{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs #crosshead path{fill:#333;stroke:#333}#mermaid-svg-1gA5YT1NwANi2tQs .messageText{fill:#333;stroke:#333}#mermaid-svg-1gA5YT1NwANi2tQs .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-1gA5YT1NwANi2tQs .labelText,#mermaid-svg-1gA5YT1NwANi2tQs .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-1gA5YT1NwANi2tQs .loopText,#mermaid-svg-1gA5YT1NwANi2tQs .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-1gA5YT1NwANi2tQs .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-1gA5YT1NwANi2tQs .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-1gA5YT1NwANi2tQs .noteText,#mermaid-svg-1gA5YT1NwANi2tQs .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-1gA5YT1NwANi2tQs .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-1gA5YT1NwANi2tQs .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-1gA5YT1NwANi2tQs .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-1gA5YT1NwANi2tQs .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .section{stroke:none;opacity:0.2}#mermaid-svg-1gA5YT1NwANi2tQs .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-1gA5YT1NwANi2tQs .section2{fill:#fff400}#mermaid-svg-1gA5YT1NwANi2tQs .section1,#mermaid-svg-1gA5YT1NwANi2tQs .section3{fill:#fff;opacity:0.2}#mermaid-svg-1gA5YT1NwANi2tQs .sectionTitle0{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .sectionTitle1{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .sectionTitle2{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .sectionTitle3{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-1gA5YT1NwANi2tQs .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .grid path{stroke-width:0}#mermaid-svg-1gA5YT1NwANi2tQs .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-1gA5YT1NwANi2tQs .task{stroke-width:2}#mermaid-svg-1gA5YT1NwANi2tQs .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .taskText:not([font-size]){font-size:11px}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-1gA5YT1NwANi2tQs .task.clickable{cursor:pointer}#mermaid-svg-1gA5YT1NwANi2tQs .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-1gA5YT1NwANi2tQs .taskText0,#mermaid-svg-1gA5YT1NwANi2tQs .taskText1,#mermaid-svg-1gA5YT1NwANi2tQs .taskText2,#mermaid-svg-1gA5YT1NwANi2tQs .taskText3{fill:#fff}#mermaid-svg-1gA5YT1NwANi2tQs .task0,#mermaid-svg-1gA5YT1NwANi2tQs .task1,#mermaid-svg-1gA5YT1NwANi2tQs .task2,#mermaid-svg-1gA5YT1NwANi2tQs .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutside0,#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutside2{fill:#000}#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutside1,#mermaid-svg-1gA5YT1NwANi2tQs .taskTextOutside3{fill:#000}#mermaid-svg-1gA5YT1NwANi2tQs .active0,#mermaid-svg-1gA5YT1NwANi2tQs .active1,#mermaid-svg-1gA5YT1NwANi2tQs .active2,#mermaid-svg-1gA5YT1NwANi2tQs .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-1gA5YT1NwANi2tQs .activeText0,#mermaid-svg-1gA5YT1NwANi2tQs .activeText1,#mermaid-svg-1gA5YT1NwANi2tQs .activeText2,#mermaid-svg-1gA5YT1NwANi2tQs .activeText3{fill:#000 !important}#mermaid-svg-1gA5YT1NwANi2tQs .done0,#mermaid-svg-1gA5YT1NwANi2tQs .done1,#mermaid-svg-1gA5YT1NwANi2tQs .done2,#mermaid-svg-1gA5YT1NwANi2tQs .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-1gA5YT1NwANi2tQs .doneText0,#mermaid-svg-1gA5YT1NwANi2tQs .doneText1,#mermaid-svg-1gA5YT1NwANi2tQs .doneText2,#mermaid-svg-1gA5YT1NwANi2tQs .doneText3{fill:#000 !important}#mermaid-svg-1gA5YT1NwANi2tQs .crit0,#mermaid-svg-1gA5YT1NwANi2tQs .crit1,#mermaid-svg-1gA5YT1NwANi2tQs .crit2,#mermaid-svg-1gA5YT1NwANi2tQs .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-1gA5YT1NwANi2tQs .activeCrit0,#mermaid-svg-1gA5YT1NwANi2tQs .activeCrit1,#mermaid-svg-1gA5YT1NwANi2tQs .activeCrit2,#mermaid-svg-1gA5YT1NwANi2tQs .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-1gA5YT1NwANi2tQs .doneCrit0,#mermaid-svg-1gA5YT1NwANi2tQs .doneCrit1,#mermaid-svg-1gA5YT1NwANi2tQs .doneCrit2,#mermaid-svg-1gA5YT1NwANi2tQs .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-1gA5YT1NwANi2tQs .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-1gA5YT1NwANi2tQs .milestoneText{font-style:italic}#mermaid-svg-1gA5YT1NwANi2tQs .doneCritText0,#mermaid-svg-1gA5YT1NwANi2tQs .doneCritText1,#mermaid-svg-1gA5YT1NwANi2tQs .doneCritText2,#mermaid-svg-1gA5YT1NwANi2tQs .doneCritText3{fill:#000 !important}#mermaid-svg-1gA5YT1NwANi2tQs .activeCritText0,#mermaid-svg-1gA5YT1NwANi2tQs .activeCritText1,#mermaid-svg-1gA5YT1NwANi2tQs .activeCritText2,#mermaid-svg-1gA5YT1NwANi2tQs .activeCritText3{fill:#000 !important}#mermaid-svg-1gA5YT1NwANi2tQs .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-1gA5YT1NwANi2tQs g.classGroup text .title{font-weight:bolder}#mermaid-svg-1gA5YT1NwANi2tQs g.clickable{cursor:pointer}#mermaid-svg-1gA5YT1NwANi2tQs g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-1gA5YT1NwANi2tQs g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-1gA5YT1NwANi2tQs .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-1gA5YT1NwANi2tQs .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-1gA5YT1NwANi2tQs .dashed-line{stroke-dasharray:3}#mermaid-svg-1gA5YT1NwANi2tQs #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs .commit-id,#mermaid-svg-1gA5YT1NwANi2tQs .commit-msg,#mermaid-svg-1gA5YT1NwANi2tQs .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-1gA5YT1NwANi2tQs g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-1gA5YT1NwANi2tQs g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-1gA5YT1NwANi2tQs g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-1gA5YT1NwANi2tQs .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-1gA5YT1NwANi2tQs .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-1gA5YT1NwANi2tQs .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-1gA5YT1NwANi2tQs .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-1gA5YT1NwANi2tQs .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-1gA5YT1NwANi2tQs .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-1gA5YT1NwANi2tQs .edgeLabel text{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-1gA5YT1NwANi2tQs .node circle.state-start{fill:black;stroke:black}#mermaid-svg-1gA5YT1NwANi2tQs .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-1gA5YT1NwANi2tQs #statediagram-barbEnd{fill:#9370db}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-state .divider{stroke:#9370db}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-1gA5YT1NwANi2tQs .note-edge{stroke-dasharray:5}#mermaid-svg-1gA5YT1NwANi2tQs .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-1gA5YT1NwANi2tQs .error-icon{fill:#522}#mermaid-svg-1gA5YT1NwANi2tQs .error-text{fill:#522;stroke:#522}#mermaid-svg-1gA5YT1NwANi2tQs .edge-thickness-normal{stroke-width:2px}#mermaid-svg-1gA5YT1NwANi2tQs .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-1gA5YT1NwANi2tQs .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-1gA5YT1NwANi2tQs .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-1gA5YT1NwANi2tQs .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-1gA5YT1NwANi2tQs .marker{fill:#333}#mermaid-svg-1gA5YT1NwANi2tQs .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-1gA5YT1NwANi2tQs {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
p
對于頭插法
List * createbyhead ( List * & L) //一個初始化過的新表
{
List * p= L;
int n;
do {
scanf ( "%d" , & n) ;
List * s= ( List * ) malloc ( sizeof ( List) ) ;
s- > next= p- > next; //新結點的下一節點指向頭結點的下一節點
p- > next= s; //新結點插入到表最頭
s- > data= n;
} while ( getchar ( ) = '\n' ) //輸入回車表示輸入完了
return p;
}
對于尾插法
List * createbytail ( List * & L) //一個初始化過的新表
{
List * tail= L; //創建一個尾指標tail
int n;
do {
scanf ( "%d" , & n) ;
List * p= ( List * ) malloc ( sizeof ( List) ) ;
p- > data= n; //p指標就是每次我們想插入的新項
tail- > next= p; ///把新項插入到表尾
tail= p; //尾指標再次向后移動
} while ( getchar ( ) = '\n' ) //輸入回車表示輸入完了
tail- > next= NULL ; //保證每次尾指標都指向NULL
return p;
}
雙向鏈表
雙向串列也可以簡稱為雙鏈表,什么是雙鏈表,類比于單鏈表,則雙鏈表就是有兩個指標的鏈表,一個指標指向后繼節點,一個指標指向前驅節點,那我們結合上面介紹的單鏈表,是不會發現,雙鏈表無非是多了個指標,定義如下:
typedef struct Doublelist{
int data;
struct Doublelist * next;
struct Doublelist * prior;
} Dlist;
所以我們用雙向鏈表進行增刪查改的時候,只需要每次兼顧它的前驅指標就是了
<style>#mermaid-svg-Bu6MyTu6tADzYNwI .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .label text{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .node rect,#mermaid-svg-Bu6MyTu6tADzYNwI .node circle,#mermaid-svg-Bu6MyTu6tADzYNwI .node ellipse,#mermaid-svg-Bu6MyTu6tADzYNwI .node polygon,#mermaid-svg-Bu6MyTu6tADzYNwI .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Bu6MyTu6tADzYNwI .node .label{text-align:center;fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .node.clickable{cursor:pointer}#mermaid-svg-Bu6MyTu6tADzYNwI .arrowheadPath{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-Bu6MyTu6tADzYNwI .flowchart-link{stroke:#333;fill:none}#mermaid-svg-Bu6MyTu6tADzYNwI .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-Bu6MyTu6tADzYNwI .edgeLabel rect{opacity:0.9}#mermaid-svg-Bu6MyTu6tADzYNwI .edgeLabel span{color:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-Bu6MyTu6tADzYNwI .cluster text{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-Bu6MyTu6tADzYNwI .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Bu6MyTu6tADzYNwI text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-Bu6MyTu6tADzYNwI .actor-line{stroke:grey}#mermaid-svg-Bu6MyTu6tADzYNwI .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-Bu6MyTu6tADzYNwI #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .sequenceNumber{fill:#fff}#mermaid-svg-Bu6MyTu6tADzYNwI #sequencenumber{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI #crosshead path{fill:#333;stroke:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .messageText{fill:#333;stroke:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-Bu6MyTu6tADzYNwI .labelText,#mermaid-svg-Bu6MyTu6tADzYNwI .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-Bu6MyTu6tADzYNwI .loopText,#mermaid-svg-Bu6MyTu6tADzYNwI .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-Bu6MyTu6tADzYNwI .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-Bu6MyTu6tADzYNwI .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Bu6MyTu6tADzYNwI .noteText,#mermaid-svg-Bu6MyTu6tADzYNwI .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-Bu6MyTu6tADzYNwI .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-Bu6MyTu6tADzYNwI .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-Bu6MyTu6tADzYNwI .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-Bu6MyTu6tADzYNwI .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .section{stroke:none;opacity:0.2}#mermaid-svg-Bu6MyTu6tADzYNwI .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-Bu6MyTu6tADzYNwI .section2{fill:#fff400}#mermaid-svg-Bu6MyTu6tADzYNwI .section1,#mermaid-svg-Bu6MyTu6tADzYNwI .section3{fill:#fff;opacity:0.2}#mermaid-svg-Bu6MyTu6tADzYNwI .sectionTitle0{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .sectionTitle1{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .sectionTitle2{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .sectionTitle3{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-Bu6MyTu6tADzYNwI .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .grid path{stroke-width:0}#mermaid-svg-Bu6MyTu6tADzYNwI .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-Bu6MyTu6tADzYNwI .task{stroke-width:2}#mermaid-svg-Bu6MyTu6tADzYNwI .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .taskText:not([font-size]){font-size:11px}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-Bu6MyTu6tADzYNwI .task.clickable{cursor:pointer}#mermaid-svg-Bu6MyTu6tADzYNwI .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-Bu6MyTu6tADzYNwI .taskText0,#mermaid-svg-Bu6MyTu6tADzYNwI .taskText1,#mermaid-svg-Bu6MyTu6tADzYNwI .taskText2,#mermaid-svg-Bu6MyTu6tADzYNwI .taskText3{fill:#fff}#mermaid-svg-Bu6MyTu6tADzYNwI .task0,#mermaid-svg-Bu6MyTu6tADzYNwI .task1,#mermaid-svg-Bu6MyTu6tADzYNwI .task2,#mermaid-svg-Bu6MyTu6tADzYNwI .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutside0,#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutside2{fill:#000}#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutside1,#mermaid-svg-Bu6MyTu6tADzYNwI .taskTextOutside3{fill:#000}#mermaid-svg-Bu6MyTu6tADzYNwI .active0,#mermaid-svg-Bu6MyTu6tADzYNwI .active1,#mermaid-svg-Bu6MyTu6tADzYNwI .active2,#mermaid-svg-Bu6MyTu6tADzYNwI .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-Bu6MyTu6tADzYNwI .activeText0,#mermaid-svg-Bu6MyTu6tADzYNwI .activeText1,#mermaid-svg-Bu6MyTu6tADzYNwI .activeText2,#mermaid-svg-Bu6MyTu6tADzYNwI .activeText3{fill:#000 !important}#mermaid-svg-Bu6MyTu6tADzYNwI .done0,#mermaid-svg-Bu6MyTu6tADzYNwI .done1,#mermaid-svg-Bu6MyTu6tADzYNwI .done2,#mermaid-svg-Bu6MyTu6tADzYNwI .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-Bu6MyTu6tADzYNwI .doneText0,#mermaid-svg-Bu6MyTu6tADzYNwI .doneText1,#mermaid-svg-Bu6MyTu6tADzYNwI .doneText2,#mermaid-svg-Bu6MyTu6tADzYNwI .doneText3{fill:#000 !important}#mermaid-svg-Bu6MyTu6tADzYNwI .crit0,#mermaid-svg-Bu6MyTu6tADzYNwI .crit1,#mermaid-svg-Bu6MyTu6tADzYNwI .crit2,#mermaid-svg-Bu6MyTu6tADzYNwI .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-Bu6MyTu6tADzYNwI .activeCrit0,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCrit1,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCrit2,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-Bu6MyTu6tADzYNwI .doneCrit0,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCrit1,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCrit2,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-Bu6MyTu6tADzYNwI .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-Bu6MyTu6tADzYNwI .milestoneText{font-style:italic}#mermaid-svg-Bu6MyTu6tADzYNwI .doneCritText0,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCritText1,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCritText2,#mermaid-svg-Bu6MyTu6tADzYNwI .doneCritText3{fill:#000 !important}#mermaid-svg-Bu6MyTu6tADzYNwI .activeCritText0,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCritText1,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCritText2,#mermaid-svg-Bu6MyTu6tADzYNwI .activeCritText3{fill:#000 !important}#mermaid-svg-Bu6MyTu6tADzYNwI .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-Bu6MyTu6tADzYNwI g.classGroup text .title{font-weight:bolder}#mermaid-svg-Bu6MyTu6tADzYNwI g.clickable{cursor:pointer}#mermaid-svg-Bu6MyTu6tADzYNwI g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Bu6MyTu6tADzYNwI g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-Bu6MyTu6tADzYNwI .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-Bu6MyTu6tADzYNwI .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Bu6MyTu6tADzYNwI .dashed-line{stroke-dasharray:3}#mermaid-svg-Bu6MyTu6tADzYNwI #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI .commit-id,#mermaid-svg-Bu6MyTu6tADzYNwI .commit-msg,#mermaid-svg-Bu6MyTu6tADzYNwI .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-Bu6MyTu6tADzYNwI g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-Bu6MyTu6tADzYNwI g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-Bu6MyTu6tADzYNwI g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-Bu6MyTu6tADzYNwI .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-Bu6MyTu6tADzYNwI .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-Bu6MyTu6tADzYNwI .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-Bu6MyTu6tADzYNwI .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-Bu6MyTu6tADzYNwI .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-Bu6MyTu6tADzYNwI .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-Bu6MyTu6tADzYNwI .edgeLabel text{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-Bu6MyTu6tADzYNwI .node circle.state-start{fill:black;stroke:black}#mermaid-svg-Bu6MyTu6tADzYNwI .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-Bu6MyTu6tADzYNwI #statediagram-barbEnd{fill:#9370db}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-state .divider{stroke:#9370db}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-Bu6MyTu6tADzYNwI .note-edge{stroke-dasharray:5}#mermaid-svg-Bu6MyTu6tADzYNwI .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-Bu6MyTu6tADzYNwI .error-icon{fill:#522}#mermaid-svg-Bu6MyTu6tADzYNwI .error-text{fill:#522;stroke:#522}#mermaid-svg-Bu6MyTu6tADzYNwI .edge-thickness-normal{stroke-width:2px}#mermaid-svg-Bu6MyTu6tADzYNwI .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-Bu6MyTu6tADzYNwI .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-Bu6MyTu6tADzYNwI .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-Bu6MyTu6tADzYNwI .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-Bu6MyTu6tADzYNwI .marker{fill:#333}#mermaid-svg-Bu6MyTu6tADzYNwI .marker.cross{stroke:#333}
:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}</style>
<style>#mermaid-svg-Bu6MyTu6tADzYNwI {
color: rgba(0, 0, 0, 0.75);
font: ;
}</style>
頭結點
a
b
c
d
雖然雙鏈表要比單鏈表更難一點,但是其實如果我們理解了的話,增刪只不過是對這三個結點的操作罷了,比如初始化init()
void init ( Dlist * & L)
{
L= ( Dlist * ) malloc ( sizeof ( Dlist) ) ;
L- > next= NULL ;
L- > prior= NULL ;
}
對于雙鏈表來說,插入是要比單鏈表難一點的,因為對于單鏈表,每次插入都是僅僅限定于插入位置前面的一項和新插入一項的兩個指標,而雙鏈表則需要考慮三個指標(前一項的next指標和新插入一項的prior指標以及next指標),但是如果理解的話也不是很難
bool insertDlist ( Dlist * & L, int n, int e)
{
if ( n< 1 )
return false ;
Dlist * p= L;
int i = 0 ;
while ( p!= NULL && i< n- 1 ) //先找要插入位置前一個結點
{
p= p- > next;
i++ ;
}
if ( p== NULL )
return false ;
Dlist * q= p- next;
Dlist * s= ( Dlist * ) malloc ( Dlist) ;
s- > data= e;
q- > prior= s;
s- > next= q;
s- > prior= p; //不要忘了指向前面的指標
p- > next= s;
return true
}
而除了增加操作,還有查找,洗掉操做等等,這里我就不在給大家用代碼展示了,希望大家能自己私下用代碼實作
回圈鏈表
回圈鏈表可以分為單回圈鏈表和雙回圈鏈表,回圈鏈表與普通鏈表不同的地方就是,回圈鏈表的尾項指回了首項 我想經過上面對單鏈表的詳細的介紹,到這里大家應該都能熟練的理解鏈表的作業原理了,所以我這里只幫大家粗略介紹下回圈鏈表,具體的細節就不再多說了 回圈鏈表的定義
typedef struct Clist{
int data;
struct Clist * next;
} ;
void init ( struct Clist * & L) //回圈鏈表里沒有任何一項會指向NULL,每一項都有所指的東西
{
L= ( struct Clist * ) malloc ( sizeof ( struct Clist) ) ;
L- > next= L;
}
至于接下來的一些介面如insert(),remove()我在這里就不再贅述了,因為大家只要掌味訓本原理,寫出來代碼還是相對比較容易的
鏈表與順序表的區別
順序表存盤資料,需預先申請一整塊足夠大的存盤空間,然后將資料按照次序逐一存盤,優點是存盤密度高,因為不需要像鏈表一樣存盤指標,但是因為它的長度是限定的,所以不利于動態調整,但是因為順序表基于陣列下標直接尋址,所以查找的速度比鏈表快,同時洗掉增加時,就沒有鏈表那么簡單的只需要對當前位置的兩個項進行操作簡單了 鏈表和順序表如何選擇? 基于存盤的考慮: 順序表的存盤空間是分配好不變的,在程式執行之前必須明確規定它的存盤空間大小,即事先對”maxsize”要有合適的設定,過大造成浪費,過小造成溢位,在對線性表的長度或存盤規模難以估計時,不宜采用順序表;鏈表不用事先估計存盤規模, 2.基于運算的考慮: 如果經常做的運算是按序號訪問資料元素,顯然順序表優于鏈表;在順序表中做插入,洗掉時,平均移動表中一半的元素,當資料元素的資訊量較大且表較長時,這一點是不應該忽視的;在鏈表中做插入,洗掉,雖然也要找插入位置,但操作主要是比較操作,從這個角度考慮顯然鏈表優于順序表, 3.基于環境的考慮: 順序表容易實作,任何高級語言中都有陣列型別,鏈表的操作是基于指標的,相對來講前者簡單些
總結
對于學習資料結構,線性表只是最基礎的,希望我能再接再勵,能搞懂其原理,最后希望大家可以點贊關注支持,謝謝~~~~