• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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: 6187
164
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: 65448
248
  • 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: 6187
164
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?
 
Bartender
Posts: 6135
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.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!