linked list - Get the index of the Node in a LinkedList which contains the given value in java -
i have linkedlist
private linkedlist<node> vertices; here class node
public class node { string value; linkedlist edges ; public node() { value=null; edges=new linkedlist(); } } now linkedlist mentioned above contains nodes in graph.what want pass string value method .this method should check if nodes in linkedlist contains node has value equal value passed .if should return index of node.
here tried do
public node getnode(string value) { int index=vertices.indexof(value);//this problem is. //index getting assigned value -1 return vertices.get(index); } and called method way
temp2=getnode(header[dest]); but call method vertices.indexof(value) returning -1 (-1 shows not have . although has node has value equal value passed) . how check nodes matches value value pass . vertices of type node , passing string value.
in node need implement equals method indexof method of linkedlist uses equals method internally compare node passed other existing nodes in list like:
public boolean equals(node othernode) { //... compare node values } you need method as:
public node getnode(node value)//or create node internally string input parameter ^^^^^
Comments
Post a Comment