Java code to find Upper and Lower number of each element in an array -
i have array [22,30,32,36,40]
i want find nearest lower , upper value each element. ex. 22 , lower value 22 ani upper value 30. 30 , lower value 22 , upper 32. 32 ,lower value 30 , upper value 36. 36, lower 32 , upper 40.and last element 40 ,lower value 36 , upper 40. array becomes [ 22-30,22-32,30-36,32-40,36-40]
put items treemap
. loop on items in original array , each of them lowerkey()
in treemap
predecessor , higherkey()
successor. if either of them null
mean it's lowest/highest , have take current element itself.
Comments
Post a Comment