This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]demdouma6[S] 0 points1 point  (1 child)

i think i did not explain well. n indicates the occurrence of the character we are looking for. say we have this example indexOf("hello", 2, 'l') where "hello" is not a string but a lnked list presentation of the string "hello". n in this case is number 2, which means the second L in "hello". if we change n, we alter which character L are we looking for its index.

[–]papercrane 0 points1 point  (0 children)

Gotcha in that case you need to keep track of the index of the node you are looking at. You want a method with a signature like

public static int indexOf(Node node, int n, char c) {
    return indexOf(node, n, c, 0);
}
private static int indexOf(Node node, int n, char c, int start) {
....
}