Category Archives: Java 8

Find depth of binary tree

import java.util.Stack; /** * Find Depth of Binary Tree * @author asharda * */ class TreeNodes { int data; TreeNodes left; TreeNodes right; TreeNodes(int data) { this.data=data; } } public class TreeDepth { static int count=0; public void depth(Stack<TreeNodes> st) … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged , | Leave a comment

Fibonnaic series using Java

  /** * Fibonnaci Series * @author asharda * */ public class Fibonnaci { public int getFib(int num) { if(num<2) { return num; } return getFib(num-1)+getFib(num-2); //return f; } public static void main(String[] args) { Fibonnaci f =new Fibonnaci(); System.out.println(“Fibonaci … Continue reading

Posted in Data Structures, Design Pattern, Java, Java 8, Uncategorized | Tagged , | Leave a comment

Find Peak Element in an array Java

  import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; /** * @author asharda * */ public class Peak { public int findPeakElement(int[] nums) { Integer[] num = new Integer[nums.length]; for (int i = 0; i < nums.length; i++) { num[i] = Integer.valueOf(nums[i]); … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged | Leave a comment

Reverse Singly LinkedList using Java

/** * Reverse LinkedList * @author asharda * */ class Node { int data; Node next; Node(int data) { this.data=data; } } public class ReverseLinkedList { static Node root; Node temp=null; public void insert(int data) { if(root==null) { root=new Node(data); … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged | Leave a comment

Implement Stack using LinkedList Java

/** * Stack * * @author asharda * */ class Nodes { int data; Nodes next; Nodes(int data) { this.data = data; } }   public class Stack { static Nodes root1; Nodes temp1 = null; public void push(int data) … Continue reading

Posted in Data Structures, Java, Java 8 | Tagged | Leave a comment

Implement Singly LinkedList using Java

/** * LinkedList * * @author asharda * */ class Node { int data; Node next; Node(int data) { this.data = data; } }   public class LinkedList { static Node root; Node temp = null; /** * Insert using … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged | Leave a comment

Sequential Search using Java

/** * Sequential Search * @author asharda * */ public class SeqSearch { /** * Check if number is present in array * @param arr * @param num * @return */ public int seqSearch(int []arr,int num) { for(int i=0;i<arr.length;i++) { … Continue reading

Posted in Java, Java 8, Uncategorized | Leave a comment