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.
1 Answer
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..