Question

This code is wrong. It must be correct according to me but I'm confusing. I have been working on this for hours. There must be something I missed. I'm very very beginner coder. I cannot think alghoritmic like you. Could you look at this?

public T set(int index, T t) {

        MyArrayListElement<T> element = getElement(index); 
        if (index < 0 || index >= size())
              throw new ArrayIndexOutOfBoundsException();
            T old = getElement(index);
            getElement(index) = t;
            return old;
    }
Was it helpful?

Solution 2

According to this:

https://github.com/tdgunes/ozucourses/tree/master/CS102/Homework%201

You must replace

getElement(index) = t;

by

set(index, t)

to set an element in your list.

OTHER TIPS

One issue I see here is the following.

You cannot assign this way: getElement(index) = t;.

The left side must be a variable.

What you need here is a call something like this.

setElement(index, t);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top