Improve Code Creating Addbefore Method Instead Adding Element End Addbefore Adds Beginning Q37072523

Improve the code belowby creating an addBefore method. Instead of adding an element tothe end, addBefore adds it to the beginning, at position 0,causing all existing elements to move forward (their positionincreased by 1). However, like add, your addBefore methodmust also guarantee that only O( ) time is needed to performn addBefores and adds. To accomplish this, aswith add, most calls toaddBefore must execute very quickly, inO(1) constant time, meaning that you can’t just shift all theelements forward by 1. The changes you make toIntArrayList should preserve the property that the get and setmethods take a constant amount of

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.