Content-Length: 2771 | pFad | http://github.com/hussien89aa/DataStructureAndAlgorithms/pull/13.diff
thub.com
diff --git a/src/com/ds/LinkedListU.java b/src/com/ds/LinkedListU.java
index b990203..5a4bbbc 100644
--- a/src/com/ds/LinkedListU.java
+++ b/src/com/ds/LinkedListU.java
@@ -3,26 +3,29 @@
public class LinkedListU {
Node head;
public LinkedListU() {
- head= null;
+ head = null;
}
-public void add(Object value){
- Node newNode=new Node(value, null);
- if(head==null)
- head=newNode;
- else{
+// function to add value of type object and its children in linked list.
+public void add(Object value) {
+ Node newNode = new Node(value, null);
+ if(head == null)
+ head = newNode;
+ else {
newNode.next=head;
- head= newNode;
+ head = newNode;
}
}
+// function to delete node of linked list.
public void delete(){
- head=head.next;
+ head = head.next;
}
+// function to display elements of the linked list.
public void display(){
- Node n=head;
- while(n!=null){
+ Node n = head;
+ while(n != null){
System.out.println((T)n.value);
- n=n.next;
+ n = n.next;
}
}
diff --git a/src/com/tree/BST.java b/src/com/tree/BST.java
index 1dec1c1..950932e 100644
--- a/src/com/tree/BST.java
+++ b/src/com/tree/BST.java
@@ -3,44 +3,45 @@
public class BST {
Node root;
public BST() {
- root=null;
+ root = null;
}
-
- public Node NodeCreate(int value){
+// this function returns the new node by settingvalue to value and child to be null.
+ public Node NodeCreate(int value) {
return new Node(value, null, null);
}
- public void add(Node start, Node newNode){
- if(root==null){
- root=newNode;
+// function to add the elements in BST.
+ public void add(Node start, Node newNode) {
+ if(root == null){
+ root = newNode;
return;
}
- if(newNode.value> start.value){
- if( start.right==null)
- start.right=newNode;
- add(start.right,newNode);
+ if(newNode.value > start.value) {
+ if( start.right == null)
+ start.right = newNode;
+ add(start.right, newNode);
}
- if(newNode.value< start.value){
- if( start.left==null)
- start.left=newNode;
- add(start.left,newNode);
+ if(newNode.value < start.value) {
+ if( start.left == null)
+ start.left = newNode;
+ add(start.left, newNode);
}
}
-
-public void Search(int value, Node start){
+// function to search the given value using recursion.
+public void Search(int value, Node start) {
- if(start==null){
- System.out.println("node isnot found");
+ if(start == null) {
+ System.out.println("node is not found");
return;
}
- if(start.value==value)
+ if(start.value == value)
{
System.out.println("node is found");
return;
}
- if( value>start.value){
+ if( value > start.value) {
Search(value, start.right);
}
- if( value
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/hussien89aa/DataStructureAndAlgorithms/pull/13.diff
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy