Given the following classes, i need to implement the delete() method, which will delete all nodes equal() to Node n. delete() should return true if at least one node could be removed, and return false otherwise. Use Java syntax.Dont use java API.
Public class DS {
public Node getStart() {
/* This method is written for you it will return the first node */
}
public void setStart(Node n) {
/* This method is written for you it will set the first node */
}
public boolean delete(Node n) { /* Provide code for this method */ }
class Node {
public boolean equal(Node n) { /* This method is written for you */ }
public Node getNext() {
/* This method is written for you it will return the next node*/
}
public Node getPrevious() {
/* This method is written for you it will return the previous node*/
}
public void setNext(Node n) {
/* This method is written for you it will set the next node*/
}
public void setPrevious(Node n) {
/* This method is written for you it will set the previous node*/
}
}
}
================================================== =====
here i'm submitting the code for delete(Node n).I'm not getting the correct results.Plz help me.
================================================== =====
public boolean delete(Node n) { /* Provide code for this method */ }
{
LinkedList myList = new LinkedList();
int var = 0;
Node head = new DS().getStart();
if (head.equal(n) )
{
head = head.getNext();
setStart(head);
var++;
}
Node n1 = null;
for (Node l = new DS().getStart() ; l != null; l = l.getNext())
{ if n1==null
if (l.equal(n))
{
n1.setNext(l.getNext());
var++;
}
}
if (var > 0)
return true;
else
return false;
}

