Question

Recall the IuregeList ADI wose interface is reproduced below. (Comments are included to rewind you what each method does) publie interfsceIntegertistInterface public boolean 1Euptyt) zeturntue iet i1st haa no elenenta public int sizet public int get lint index): zeturn liat element at index pubiie wosd add(int index, int newicey nsert neuiten at index pablic voad renove (int index)ideleze element a public road renoveRlOeet list to empty state zeturn nunber of elements in list t index 2. Write a static void method called reverse with the following heading that reverses the order of the items in the list. Use only the ADT operniouis above and function swapfiom poblem I to do this. Do this using a Joop, nol recusion pubiic static oid reverse lIntegerlist 115t

0 0
Add a comment Improve this question Transcribed image text
Answer #1
static void swap(IntegerListInterface list, int i, int j) {
    int value = list.get(i);
    list.remove(i);
    list.add(i, list.get(j));
    list.remove(j);
    list.add(j, value);
}

public static void reverse(IntegerListInterface list) {
    for(int i = 0; i <= list.size()/2; ++i) {
        swap(list, i, list.size()-i-1);
    }
}
Add a comment
Know the answer?
Add Answer to:
Recall the IuregeList ADI wose interface is reproduced below. (Comments are included to rewind you what...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT