Kulwinder Singh
06/27/2021, 4:06 PMprevItems
and nextItems
of below data class , i have tried recursion
but it caused infinite loop because we have to find next and previous both but if i try with either previous or next then there is no infinite loop.
data class Root(val item: Int, val prevItems: List<Root>, val nextItems: List<Root>)
Suppose i have data for item
is => 1,2,3,4,5 then result i wanted is =>
Root(item: 1, prevItems: [], nextItems: [2,3,4,5])
Root(item: 2, prevItems: [1], nextItems: [3,4,5])
Root(item: 3, prevItems: [1,2], nextItems: [4,5])
Root(item: 4, prevItems: [1,2,3], nextItems: [5])
Root(item: 5, prevItems: [1,2,3,4], nextItems: [])
*for making it short i am using 1,2,3… in prevItems/nextItems instead of Root
object
what approach should i use to calculate above? also is there any kotlin collection function can help here ?CLOVIS
06/27/2021, 6:12 PMCLOVIS
06/27/2021, 6:13 PMBig Chungus
06/27/2021, 8:32 PMBig Chungus
06/27/2021, 8:33 PMCLOVIS
06/27/2021, 9:53 PMKulwinder Singh
06/28/2021, 2:02 AMRoukanken
06/28/2021, 5:56 AMSourabh Rawat
06/28/2021, 11:02 AMRoukanken
06/28/2021, 11:08 AMbsimmons
06/28/2021, 1:32 PMDoubleLinkedList.subList(i, j)
to avoid N^2 memory usage.nkiesel
06/29/2021, 6:27 AMRoot
objects out of a list of <n> items? Or do you want a function that creates a single Root
object out of a list of items and a given item?