Skip to content

2 issues in Linked List #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
prakashn27 opened this issue Dec 18, 2014 · 7 comments
Closed

2 issues in Linked List #1

prakashn27 opened this issue Dec 18, 2014 · 7 comments
Assignees

Comments

@prakashn27
Copy link
Contributor

  1. I get 0 entry by default in the linked list.
    if i add 10 i get an entry of 10 , 0

  2. insert tail is not working
    i followed the same concept as insert first but it is not working

@prakashn27
Copy link
Contributor Author

this is in LinkedList.java
FYI i changed my implementation in LinkedListNode.java but wanted to know where i go wrong

@santhoshvai
Copy link
Contributor

this issue is only in java file right? Cos i remember that i tested my c files

@santhoshvai
Copy link
Contributor

And seperate the java implementation and c implementation by separate folders if you can

@santhoshvai
Copy link
Contributor

I have fixed the issue with the new commit, do a git pull origin master to get it

@santhoshvai
Copy link
Contributor

the issue is with

Node head = new Node();
Node tail = new Node();

this means that the head is never null and you cant enter the if loop in line 25. since head and tail have global scope just declaring them is enough to assigning null to the object. I hope this answers your question. LinkedList.java is an elegant implementation in my opinion than the other one. Do implement some JUnit test cases for the code and push it in the repo soon.

@santhoshvai
Copy link
Contributor

for this reason the constructor is also useless!

@santhoshvai
Copy link
Contributor

We can improve the elgance more by using Null object pattern.. this eliminates the risk of comparing null and would have saved you from this issue in the first place... Take this is as a small exercise and implement this code with this pattern. I leave this to you.

@santhoshvai santhoshvai self-assigned this Dec 18, 2014
prakashn27 added a commit that referenced this issue Jan 15, 2015
…ructures

* 'master' of https://github.com/AlgorithmCrackers/Data-Structures:
  fixes #1 also the useless constructor is removed
  Seperation of java and c implementation

Conflicts:
	Linked-Lists/Java/LinkedList.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants