Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EASY JAVA Q : PLEASE HELP! so i have an Array List called \"contains\" it contai

ID: 3804142 • Letter: E

Question

EASY JAVA Q : PLEASE HELP!

so i have an Array List called "contains"

it contains objects with many properties (like id #, size, and priority)

which leads to my question.... after enough objects are inserted to this array, I want to delete the object with the highest priority from the array list

But the problem is I cant do this by index! (cant simply say contains.remove(index i know has highest priority) because the indexes will change and i wont be

able to keep track of what they change to .

I need a loop or something to look through the array list and remove the specifc object in it with the highest priority .

thanks!

Explanation / Answer

You can do one thing.

While inserting new object, insert in such a way such that it always sorted by their priority value.

insert(newdata,arraylist)

if arraylist.empty ==true:

arraylist.insert(newdata)

return

arraylist.insert(newdata)

currentindex =0

while(currentindex < size(arraylist) and newdata.priority > arraylist[currentindex].priority)

currentindex++

saveindex =currentindex

i = size(arraylist) -2

while(i>=saveindex)

arraylist[i+1] =arraylilst[i]

arraylist[saveindex] = newdata

I wrote the pseudo code above