Created
July 18, 2018 15:34
-
-
Save ashishkumarsinghh/cfb9f27b9122c4de9167085fd5ed8415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SelfPractice; | |
public class SLLNode{ | |
int data; | |
SLLNode next; | |
SLLNode(int data){ | |
this.data = data; | |
this.next = null; | |
} | |
SLLNode(){ | |
this.data = -1; | |
this.next = null; | |
} | |
public SLLNode addAtEnd(SLLNode node){ | |
if(this.data != -1){ | |
SLLNode curr = this; | |
while(curr.next != null){ | |
curr = curr.next; | |
} | |
curr.next = node; | |
return this; | |
} | |
else{ | |
this.data = node.data; | |
return this; | |
} | |
} | |
public void printLL(){ | |
SLLNode node = this; | |
while(node != null){ | |
System.out.print(node.data +"-->"); | |
node = node.next; | |
} | |
System.out.print("NULL"); | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment