6
主要問題:將項目插入已使用Julia排序的列表中的最快方式是什麼?將項目插入Julia的排序列表(帶和不帶重複項)
目前,我這樣做:
v = [1, 2, 3, 5] #example list
x = 4 #value to insert
index = searchsortedfirst(v, x) #find index at which to insert x
insert!(v, index, x) #insert x at index
獎金問題:如果我想同時保證沒有重複怎麼辦?
謝謝,這非常整齊。 – 2014-09-06 05:58:44
我改變了拼接!以允許替換參數是任何可枚舉的,其中包括標量值:https://github.com/JuliaLang/julia/commit/e048f2bf1b8da56b07738c0a4d142cd29e140e98。你現在可以定義'insert_and_dedup!(v :: Vector,x)=(splice!(v,searchsorted(v,x),x); v)'。 – StefanKarpinski 2014-09-17 14:49:42
謝謝,也感謝你在朱莉婭的所有工作。我很喜歡這門語言。 – 2014-09-18 06:43:40