Hi. The task is to insert an element into a structure which keeps a decreasing / increasing order in terms of a certain property, say height, of the elements in the structure. One way to do it, is to use vector / list structure. The operations which are constantly used, are
pop!(myList) # remove and return the last element from myList i = something(findlast( e -> e.time >= elementToBeInserted.height, myList ), 0) +1 # compare the element to be inserted to all the elements in list myList one by one to get a vector of values true or false. findlast will return the index of the last true value in this vector. Together with the something function, will return 0 if there is no true values in the created vector. insert!(myList, i, elementToBeInserted) # insert the elementToBeInserted to the i-th position of the list myList
It looks like a priority queue would be much better. What is your opinion about this then?