Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating a indexOf method for the LinkedList that I created by myself.
public int indexOf(int value) {
int index = 0;
var current = head;
while (current != null) { // baştan sonra kadar git
// eğer tutulan değer aranan değerse indeksini dön
if (current.data == value) return index;
current = current.next; // değilse bir sonraki düğüme geç
index++; // her geçişte indeksi bir arttır
}
return -1; // aranan eleman listede yoksa -1 dön
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.