• Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Can anybody please help me verify my code?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please help me verify my code. I tried writing this code and it works properly, since I am new to this coding, I am not having confidence that I have written the correct logic and I am dependent on others to check whether I am right.
Thank you in advance.

 
Sheriff
Posts: 6127
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would be better written:
Use the Interface instead of the concrete class so that the implementation of Map can change without hurting the code.
having an instance variable after the constructor is not standard.  The name of the variable should be end (lowercase).  And using Strings as flags is not a good thing.  A boolean would work fine here -- Enums would work for more complex flags.
This is confusing. Why not set node.End when i == element.length() - 1 ?  It looks like you do this twice.
 
Marshal
Posts: 65108
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Divyadharshini Karthikeyan wrote:. . . I am not having confidence that I have written the correct logic . . .

Please start by explaining what the logic should be. Don't use any “computing” words in that description.
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Knute Snortum
Thank you fro your suggestions.

i==element.length-1,
can do this too, but I tried to allocate one trienode just to indicate the end of word as True.
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt is it possible to implement Trie deletion in non recursive method in Java? "if yes,can you please post the code, because I can't find one in internet.
 
Knute Snortum
Sheriff
Posts: 6127
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think you could just roll through nodes, following their next-node, and keeping track of the previous node.  When you find the node to delete, set the previous-node's next-node to the node-to-delete's next-node.  Then, just for safety, I'd set the node-to-delete's next-node to null.  Wouldn't that work?
 
Saloon Keeper
Posts: 6049
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'temp' should be a local variable and not an instance variable (aka field).

Why have 'root'? Wouldn't that be 'this' instead?
 
Divyadharshini Karthikeyan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@knute snortum,
Thank you for your suggestions and will sure give a try with this logic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!