模板 資料結構 鍊錶 LinkedList

2022-03-05 16:35:27 字數 679 閱讀 5472

乙個只供刪除的雙向鍊錶,為了簡單不再引入head節點,而且也不進行next的套娃操作。空間使用略微多了一些,但是無傷大雅。

struct linkedlist 

prev[1] = -1;

next[n] = -1;

}void remove(int x)

};

正常的鍊錶是單向鍊錶,刪除操作是刪除當前節點的下乙個節點,沒有必要。全部寫雙向的。b事多還可以寫個垃圾**。

struct linkedlist 

int insert(int x)

return insert(prev[tail]);

}void remove(int x)

};

並查集實現的偽鍊錶。用並查集實現的偽鍊錶雖然刪除不是o(1)的,但是不會怕訪問到被刪除的節點。

struct prevlinkedlist 

}int prev(int x)

return r;

}void remove(int x)

};

要使用next的話就再搞另乙個偽鍊錶就可以了。和只使用lower_bound,upper_bound,prev,next的平衡樹相比,偽鍊錶的速度卓越,缺點是不能插入,也不能維護第k大/前k項和。

資料結構中煉表模板

include include typedef struct node node 鍊錶輸出 void output node head printf r n 鍊錶建立 node creat head pstnext null p head while cycle s ndate date p pst...

資料結構 類模板實現鍊錶

鍊錶節點 templateclass linknode 鍊錶 templateclass linklist 指定位置插入 void inset linklist int pos,t data 建立新的節點 linknode newnode new linknode newnode data data...

Acwing資料結構 鍊錶,棧,佇列模板

單鏈表 模板題 acwing 826.單鏈表 head儲存煉表頭,e儲存節點的值,ne儲存節點的next指標,idx表示當前用到了哪個節點 int head,e n ne n idx 初始化 void init 在煉表頭插入乙個數a void insert int a 將頭結點刪除,需要保證頭結點存...