Skip to content

Comments

Fixing ListFun.addEle with position#2

Open
jolages wants to merge 1 commit intobasicsstrong:mainfrom
jolages:main
Open

Fixing ListFun.addEle with position#2
jolages wants to merge 1 commit intobasicsstrong:mainfrom
jolages:main

Conversation

@jolages
Copy link

@jolages jolages commented Jan 26, 2022

First, the add is 1 indexed instead of 0 indexed like other structures would be (and as the remove is)

This test case for example:

ListFun<Integer> list1 = ListFun.list(3, 6, 9, 8);
list1.addEle(3, 25).forEach(System.out::println);

Will give: 3, 3, 25, 6, 9, 8 (the head is repeated twice).

This will happen for any index greater than 2.

Also, this part:

if(pos == 0)
   return this.tail().addEle(ele);

Would replace the object at the given position with the new value instead of adding it and keeping the other elements of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant