0

How Can I add an element based on position to a list?

There's a method addElement(Element newElement it position) ... the first element should be at position 1 not 0. If the list is empty then the element should be added at first one. If the position isn't available (too big or too small) then the element shouldn't be added. I would be really grateful & appreciate it if someone could help me.

14th Nov 2018, 1:06 PM
Sin
1 ответ
0
you write your code to do that.. let say the is a list p = [1, 2, 3, 4, 5] the first element is 1 and it's index is 0, but you want to enter 1 for the first element, let the index be x, so index becomes, in general, x - 1.. p[0] = p[x -1], when. you enter x as 1..
5th Dec 2018, 11:11 PM
Otumian Empire
Otumian Empire - avatar