java - Searching Linked lists of an Array and removing a link -
i have array of linked lists, , use 2 loops search through each linked list on array. tips on how remove item when have found it?
public userapp(int max){ a= new user[max]; nelems=0; } int maxsize=100; userapp arr; arr= new userapp(maxsize); arr.insert("evans", "patty", 24); // insert 10 items arr.insert("smith", "doc", 59); arr.insert("smith", "lorraine", 37); arr.insert("smith", "paul", 37); arr.insert("yee", "tom", 43); arr.insert("hash", "doc", 21); arr.insert("stimson", "john", 29); arr.insert("evans", "jose", 72); arr.insert("yang", "doc", 22); arr.insert("creswell", "lucinda", 18); linkedlist[] mylist = new linkedlist[3]; mylist[0] = new linkedlist(); mylist[0].add(a[1]); mylist[0].add(a[2]); mylist[0].add(a[3]); mylist[1] = new linkedlist(); mylist[1].add(a[4]); mylist[1].add(a[3]); mylist[2] = new linkedlist(); mylist[2].add(a[2]); mylist[2].add(a[9]); public void deletefromlist(user found){ (int i=0; i<mylist.length; i++){ (int j=0; j<mylist[i].size(); j++){ if (mylist[i].listiterator(j).next().equals(found)); // delete
iterating on array done right.
to iterate on elements of linked list should use iterator() uses remove() method remove elements list while iterating on it.
Comments
Post a Comment