Bookmark Topic Watch Topic
  • New Topic

Java-LinkedList  RSS feed

 
Komali Tanvir
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have setStart(),getStart(),setNext(),getNext(), delete(Node n), setPrevious(),getPrevious() methods in my class.I need to implement delete() method with the above existing methods. means without using java API i need to implement delete() method.i have written some code for delete().but it is not working properly.

The delete(Node n) method should delete all the nodes which are equal to Node'n'.It deletes only one occurance of 'n'.but not all occurences of 'n'.
The delete(Node n) method should return true if at least one node could be removed, and return false otherwise.

My code for delete()
====================

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 (l.equal(n))
{
n1.setNext(l.getNext());
var++;

}
}
if (var > 0)
return true;
else
return false;

}
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Report post to moderator
This looks suspiciously like this question, although the user names are different.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
And coming from the same IP address, so let's continue the discussion in the other thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!