Saturday 15 March 2014

java - Linked list : Method to verify if the list contains an element? -



java - Linked list : Method to verify if the list contains an element? -

i writing method suposed homecoming true if element in linked list or false if it's not in list.

i wondering if there much more neater way code ...

here's quick view of code :

public boolean estelement(t item) { boolean elmexist = false; this.actual = this.head; if (item != null && this.actual != null) { t elmsearch; while (this.actual != null && !elmexist) { elmsearch = actual.getelement(); if (elmsearch.equals(item)) { elmexist = true; } else { this.actual = this.actual.nextlink(); } } } homecoming elmexist; }

exist loop , function element found :

while (this.actual != null && !elmexist) { elmsearch = actual.getelement(); if (elmsearch.equals(item)) homecoming true; this.actual = this.actual.nextlink(); } homecoming false;

java list

No comments:

Post a Comment