Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Java-LinkedList

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;

}
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This looks suspiciously like this question, although the user names are different.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
And coming from the same IP address, so let's continue the discussion in the other thread.
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic