Java Data Structure Implementation : Balanced BST(AVL Tree)

This program demonstrates the Balanced Binary Tree implementation in Java. The Operation which has been implemented are –

1. Insert Into Binary Tree
2. Balance Tree Automatically After Insertion
3. LL, LR, RR, RL Rotations Implemented

Find the Java Code below :

import java.util.Scanner;

/*
* This class demonstrates Balanced Binary Tree (AVL Tree) Implementation in java with Insert/Delete Operations.
* @author : Madan Gopal Singh
* @version : 1.0
* @date : 22nd March, 2013
*/
public class AVLTree {
AVLTree left;
int id;
AVLTree right;
int height;
int balanceFactor;

public AVLTree() {
}

public AVLTree(int id){
left = null;
this.id = id;
right = null;
}

public AVLTree(AVLTree left,int id,AVLTree right){
this.left = left;
this.id =id;
this.right = right;
}

/**
* This method rotates the Left to balance the binary tree.
* @param rootNode The Starting node of Tree.
* @return AVLTree.
*/
public static AVLTree rotateLeftLeft(AVLTree rootNode){
AVLTree tempNode;
tempNode = rootNode.left;
rootNode.left = tempNode.right;
tempNode.right = rootNode;
return tempNode;
}

/**
* This method rotates the Right to balance the binary tree.
* @param rootNode The Starting node of Tree.
* @return AVLTree.
*/
public static AVLTree rotateRightRight(AVLTree rootNode){
AVLTree tempNode;
tempNode = rootNode.right;
rootNode.right = tempNode.left;
tempNode.left = rootNode;
return tempNode;
}

/**
* This method rotates the Left first the Right to balance the binary tree.
* @param rootNode The Starting node of Tree.
* @return AVLTree.
*/
public static AVLTree rotateLeftRight(AVLTree rootNode){
AVLTree tempNode;
tempNode = rootNode.left;
rootNode.left = AVLTree.rotateRightRight(tempNode);
return AVLTree.rotateLeftLeft(rootNode);
}

/**
* This method rotates the Right first then Left to balance the binary tree.
* @param rootNode The Starting node of Tree.
* @return AVLTree.
*/
public static AVLTree rotateRightLeft(AVLTree rootNode){
AVLTree tempNode;
tempNode = rootNode.right;
rootNode.right = AVLTree.rotateLeftLeft(tempNode);
return AVLTree.rotateRightRight(rootNode);
}

/**
* This method returns the height of the binary tree.
* @param rootNode The Starting node of Tree.
* @return integer.
*/
public static int getHeight(AVLTree rootNode){
if(rootNode == null){
return 0;
}
if(rootNode.left == null && rootNode.right == null){
return 1;
}else{
return 1+AVLTree.maximum(AVLTree.getHeight(rootNode.left),AVLTree.getHeight(rootNode.right));
}
}

/**
* This method maximum between two heights of the Binary Tree.
* @param rootNode The Starting node of Tree.
* @return integer.
*/
public static int maximum(int height1,int height2){
if(height1>=height2)
return height1;
else
return height2;
}

/**
* This method returns the balance factor of the node of binary tree.
* @param rootNode The Starting node of Tree.
* @return integer.
*/
public static int getBalanceFactor(AVLTree rootNode){
if(rootNode == null)
return 0;
else
return (AVLTree.getHeight(rootNode.left)-AVLTree.getHeight(rootNode.right));
}

/**
* This method balances the binary tree.
* @param rootNode The Starting node of Tree.
* @return AVLTree.
*/
public static AVLTree balanceTree(AVLTree rootNode){
int balanceFactor = AVLTree.getBalanceFactor(rootNode);
int balanceFactorSubNode;
AVLTree tempNode = null;
if(balanceFactor>1){
balanceFactorSubNode = AVLTree.getBalanceFactor(rootNode.left);
if(balanceFactorSubNode>0){
System.out.println("Rotating Left Left");
tempNode = AVLTree.rotateLeftLeft(rootNode);
}else{
System.out.println("Rotating left Right");
tempNode = AVLTree.rotateLeftRight(rootNode);
}
return tempNode;
}else{
if(balanceFactor0){
System.out.println("Rotating Right Left");
tempNode = AVLTree.rotateRightLeft(rootNode);
}else{
System.out.println("Rotating Right Right");
tempNode = AVLTree.rotateRightRight(rootNode);
}
return tempNode;
}
}
return rootNode;
}

/**
* This method add a new node into the balanced binary tree (AVL Tree).
* @param rootNode The Starting node of Tree.
* @param toBeInsertedNodeId The node which you want to insert
* @return AVLTree.
*/
public static AVLTree insertNewNodeInAVLTree(AVLTree rootNode,int toBeInsertedNodeId){
AVLTree tempRootNode = rootNode;
if(rootNode.left==null && rootNode.right==null){
if(toBeInsertedNodeId<=rootNode.id){
System.out.println("Inserting Left Branch");
rootNode.left = new AVLTree(toBeInsertedNodeId);
}else{
System.out.println("Inserting Right Branch");
rootNode.right = new AVLTree(toBeInsertedNodeId);
}
}else{
if(toBeInsertedNodeId<=rootNode.id){
if(rootNode.left==null){
System.out.println("Inserting into Left Subtree");
rootNode.left = new AVLTree(toBeInsertedNodeId);
}else{
System.out.println("Traversing Left Subtree");
rootNode = insertNewNodeInAVLTree(rootNode.left, toBeInsertedNodeId);
}
}else{
if(rootNode.right==null){
System.out.println("Inserting into Right Subtree");
rootNode.right = new AVLTree(toBeInsertedNodeId);
}else{
System.out.println("Traversing Right Subtree");
rootNode = insertNewNodeInAVLTree(rootNode.right, toBeInsertedNodeId);
}
}
}
return tempRootNode;
}

/**
* This method performs preorder travarsal of the binary tree.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static AVLTree treePreOrderTraversal(AVLTree root){
System.out.print(root.id+" ");
if(root.left==null&&root.right==null){
return root;
}else{
if(root.left!=null){
AVLTree.treePreOrderTraversal(root.left);
}
if(root.right!=null){
AVLTree.treePreOrderTraversal(root.right);
}
}
return root;
}

/**
* Main Method
* @param args command line argument list
* @return void.
*/
public static void main(String[] args) {
AVLTree rootNode = null;
int nodeId = 0,userOperation=0;
String mainMenuString = "";
Scanner sc = new Scanner(System.in);
do{
mainMenuString = "What operation you want to perform on AVL Tree?"+
"\n 1. Insert New Node "+
"\n 2. Delete a Node"+
"\n 3. Preorder Traversal"+
"\n -1. Exit from Menu"+
"\n Please enter Operation Number : ";
System.out.println(mainMenuString);
userOperation = sc.nextInt();
switch(userOperation){
case 1:
System.out.println("Please enter the Node Id to which you want to insert : ");
nodeId = sc.nextInt();
if(rootNode==null){
rootNode = new AVLTree(nodeId);
}else{
AVLTree.insertNewNodeInAVLTree(rootNode, nodeId);
System.out.println("Height of Root Node after Insertion is :-"+AVLTree.getHeight(rootNode));
System.out.println("BalanceFactor of Root Node after Insertion is :-"+AVLTree.getBalanceFactor(rootNode));
rootNode = AVLTree.balanceTree(rootNode);
}
break;
case 2:
System.out.println("Please enter the Node Id of which you want to delete : ");
nodeId = sc.nextInt();
//AVLTree.deleteNodeFromAVLTree(rootNode,nodeId);
System.out.println("Similar to Tree Deletion. Kindly read my BST Post");
break;
case 3:
System.out.println("Preorder traversal sequence : ");
if(rootNode!=null){
AVLTree.treePreOrderTraversal(rootNode);
}else{
System.out.println("No node to traversal.");
}
break;
case -1:
System.out.println("Exit Application");
System.exit(0);
break;
default:
System.out.println("Invalid Operation!! Please try again");
}
}while(userOperation!=-1);
}
}

Any Optimization/Suggestions are invited.

Java Data Structure Implementation : Stack using Array

This program demonstrates the Stack implementation using Array in Java. The Push, Pop, Print Elements Operation has been implemented.

Find the Java Code below :

import java.util.Scanner;

/*
* This class demonstrates Stack Implementation using Array in java with Push/Pop/Print Operations.
* @author : Madan Gopal Singh
* @version : 2.0
* @date : 11th April, 2014
*/

public class StackUsingArray {

public static Object[] stackElements;
public static int top = -1;
public static int STACK_SIZE = 5;

/**
* This method push the element from the stack.
* @param void.
* @return void.
*/
public static void push(Object insertElement){
if(top==STACK_SIZE-1){
System.out.println("Stack Overflow");
}else{
top=top+1;
stackElements[top] = insertElement;
Object insertedElement = stackElements[top];
System.out.println("Top of Stack : "+top);
System.out.println(insertedElement.toString()+" inserted at top of stack");
}
}

/**
* This method pop the element from the stack.
* @param void.
* @return void.
*/
public static Object pop(){
if(top==-1){
System.out.println("Stack Underflow");
return null;
}else{
Object deletedElement = stackElements[top];
System.out.println(deletedElement.toString()+" deleted from top of stack");
top = top-1;
return deletedElement;
}
}

/**
* This method print all elements of the stack.
* @param void.
* @return void.
*/
public static void printAllElements(){
System.out.println("Printing element from top "+top);
if(top == -1){
System.out.println("Stack has no element");
}else{
int i = top;
while(i>=0){
System.out.println("Element at position "+ i + "is :- "+stackElements[i].toString());
i = i-1;
}
}
}

/**
* This method to check whether element already exists or not.
* @param Object.
* @return boolean.
*/
public static boolean isElementExists(Object obj){
if(top==-1){
return false;
}else{
int i = top;
while(i>=0){
if(stackElements[i].toString().equalsIgnoreCase((String)obj.toString())){
return true;
}
i = i-1;
}
return false;
}
}

/**
* This method to check whether stack is empty or not.
* @return boolean.
*/
public static boolean isEmpty(){
if(top==-1){
return true;
}else{
return false;
}
}

/**
* Main Method
* @param args command line argument list
* @return void.
*/
public static void main(String[] args) {
stackElements = new Object[STACK_SIZE];
int userOperation=0;
String mainMenuString = "";
Scanner sc = new Scanner(System.in);
do{
mainMenuString = "What operation you want to perform?"+
"\n 1. Push Element "+
"\n 2. Pop Element "+
"\n 3. Print All Elements "+
"\n 4. Cheque Element Exists Or Not "+
"\n -1. Exit from Menu"+
"\n Please enter Operation Number :";
System.out.println(mainMenuString);
userOperation = sc.nextInt();
switch (userOperation) {
case 1:
System.out.println("Please enter element to push into stack?");
String pushElement = sc.next();
StackUsingArray.push(pushElement);
break;
case 2:
StackUsingArray.pop();
break;
case 3:
StackUsingArray.printAllElements();
break;
case 4:
System.out.println("Please enter element to check Existency?");
boolean isExists = StackUsingArray.isElementExists(sc.next());
if(isExists){
System.out.println("Exists");
}else{
System.out.println("Not Exists");
}
break;
case -1:
System.out.println("Exit Application");
System.exit(0);
default:
System.out.println("Please enter a valid operation number");
}
}while(userOperation!=-1);

}

}

Any suggestion is invited if any.

Java Data Structure Implementation : Binary Search Tree

This program demonstrates the Binary Tree implementation in Java. The Insert, Delete, Traversal (Preorder,Inorder,Postorder) Operation has been implemented.

Find the Java Code below :

import java.util.Scanner;

/*
* This class demonstrates Binary Tree Implementation in java with Insert/Traversal/Delete Operations.
* @author : Madan Gopal Singh
* @version : 2.0
* @date : 16th March, 2013
*/
public class Tree {
Tree left;
int id;
Tree right;
static Tree prevNode;
static Tree permanentRoot;

public Tree() {
}
public Tree(int id){
left = null;
this.id = id;
right = null;
}
public Tree(Tree left,int id,Tree right){
this.left = left;
this.id =id;
this.right = right;
}
/**
* This method add a new node into the binary tree.
* @param rootNode The Starting node of Tree.
* @param toBeInsertedNodeId The node which you want to insert
* @return Tree.
*/
public static Tree insertNewNodeInTree(Tree rootNode,int toBeInsertedNodeId){
Tree tempRootNode = rootNode;
if(rootNode.left==null && rootNode.right==null){
if(toBeInsertedNodeId<=rootNode.id){
System.out.println("Inserting Left Branch");
rootNode.left = new Tree(toBeInsertedNodeId);
}else{
System.out.println("Inserting Right Branch");
rootNode.right = new Tree(toBeInsertedNodeId);
}
}else{
if(toBeInsertedNodeId<=rootNode.id){
if(rootNode.left==null){
System.out.println("Inserting into Left Subtree");
rootNode.left = new Tree(toBeInsertedNodeId);
}else{
System.out.println("Traversing Left Subtree");
rootNode = insertNewNodeInTree(rootNode.left, toBeInsertedNodeId);
}
}else{
if(rootNode.right==null){
System.out.println("Inserting into Right Subtree");
rootNode.right = new Tree(toBeInsertedNodeId);
}else{
System.out.println("Traversing Right Subtree");
rootNode = insertNewNodeInTree(rootNode.right, toBeInsertedNodeId);
}
}
}
return tempRootNode;
}
/**
* This method performs preorder travarsal of the binary tree.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static Tree treePreOrderTraversal(Tree root){
System.out.print(root.id+" ");
if(root.left==null&&root.right==null){
return root;
}else{
if(root.left!=null){
treePreOrderTraversal(root.left);
}
if(root.right!=null){
treePreOrderTraversal(root.right);
}
}
return root;
}
/**
* This method performs inorder travarsal of the binary tree.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static Tree treePostOrderTraversal(Tree root){
if(root.left==null&&root.right==null){
System.out.print(root.id+" ");
return root;
}else{
if(root.left!=null){
treePostOrderTraversal(root.left);
}
if(root.right!=null){
treePostOrderTraversal(root.right);
}
System.out.print(root.id+" ");
}
return root;
}
/**
* This method performs postorder travarsal of the binary tree.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static Tree treeInOrderTraversal(Tree root){
if(root.left==null&&root.right==null){
System.out.print(root.id+" ");
return root;
}else{
if(root.left!=null){
treeInOrderTraversal(root.left);
}
System.out.print(root.id+" ");
if(root.right!=null){
treeInOrderTraversal(root.right);
}
}
return root;
}
/**
* This method performs removal of node from the binary tree.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static Tree deleteNodeFromTree(Tree root,int nodeIdOfWhichDelete){
if(root == null){
System.out.println("No root found Please try later.");
return null;
}
System.out.println("Callee Id : "+root.id);
if(nodeIdOfWhichDelete!=root.id)
permanentRoot = root;
Tree minimumNode = null;
if(root.id==nodeIdOfWhichDelete){
if(root.left==null && root.right==null){
System.out.println("Deleting Leaf Node");
if(nodeIdOfWhichDelete<permanentRoot.id)
permanentRoot.left=null;
else
permanentRoot.right=null;
return root;
}else{
if(root.left==null){
System.out.println("Looking for node which have one node as child in right sub tree");
System.out.println("Permanent Root ID : "+permanentRoot.id);
System.out.println("Root in right branch");
permanentRoot.left=root.right;
}else{
if(root.right==null){
System.out.println("Looking for node which have one node as child in left sub tree");
System.out.println("Permanent Root ID : "+permanentRoot.id);
System.out.println("Root in left branch");
permanentRoot.right=root.left;
}else{
if(root.right.left!=null){
System.out.println("Looking for node which have exactly two child");
minimumNode = Tree.getMinimumElementFromRightTree(root.right);
System.out.println("Root of Minimum : "+prevNode.id);
System.out.println("Minimum Node in right sub tree : "+minimumNode.id);
root.id = minimumNode.id;
prevNode.left = minimumNode.right;
}else{
System.out.println("Looking for node which have exactly two child");
minimumNode = Tree.getMinimumElementFromRightTree(root.right);
System.out.println("Root of Minimum : "+prevNode.id);
System.out.println("Minimum Node in right sub tree : "+minimumNode.id);
root.id = minimumNode.id;
root.right = minimumNode.right;
}
}
}
}
}else{
if(nodeIdOfWhichDelete<root.id){
System.out.println("Traversing left Subtree");
Tree.deleteNodeFromTree(root.left, nodeIdOfWhichDelete);
}else{
System.out.println("Traversing right Subtree");
Tree.deleteNodeFromTree(root.right, nodeIdOfWhichDelete);
}
}
return permanentRoot;
//System.out.println(Tree.getMinimumElementFromRightTree(root).id);
}

/**
* This method minimum element from left subtree of specified Node.
* @param rootNode The Starting node of Tree.
* @return Tree.
*/
public static Tree getMinimumElementFromRightTree(Tree root){
if(root.left==null){
return root;
}else{
prevNode = root;
return getMinimumElementFromRightTree(root.left);
}
}

/**
* Main Method
* @param args command line argument list
* @return void.
*/
public static void main(String[] args) {
Tree rootNode = null;
int nodeId = 0,userOperation=0;
String mainMenuString = "";
Scanner sc = new Scanner(System.in);
do{
mainMenuString = "What operation you want to perform?"+
"\n 1. Insert New Node "+
"\n 2. Preorder Traversal"+
"\n 3. Inorder Traversal"+
"\n 4. Postorder Traversal"+
"\n 5. Delete a Node"+
"\n -1. Exit from Menu"+
"\n Please enter Operation Number : ";
System.out.println(mainMenuString);
userOperation = sc.nextInt();
switch(userOperation){
case 1:
System.out.println("Please enter the Node Id to which you want to insert : ");
nodeId = sc.nextInt();
if(rootNode==null){
rootNode = new Tree(nodeId);
}else{
Tree.insertNewNodeInTree(rootNode, nodeId);
}
break;
case 2:
System.out.println("Preorder traversal sequence : ");
if(rootNode!=null){
Tree.treePreOrderTraversal(rootNode);
}else{
System.out.println("No node to traversal.");
}
break;
case 3:
System.out.println("Inorder traversal sequence : ");
if(rootNode!=null){
Tree.treeInOrderTraversal(rootNode);
}else{
System.out.println("No node to traversal.");
}
break;
case 4:
System.out.println("Postorder traversal sequence : ");
if(rootNode!=null){
Tree.treePostOrderTraversal(rootNode);
}else{
System.out.println("No node to traversal.");
}
break;
case 5:
System.out.println("Please enter the Node Id of which you want to delete : ");
nodeId = sc.nextInt();
Tree.deleteNodeFromTree(rootNode,nodeId);
break;
case -1:
System.out.println("Exit Application");
System.exit(0);
break;
default:
System.out.println("Invalid Operation!! Please try again");
}
}while(userOperation!=-1);
}
}

Any suggestion is invited if any.

Java Data Structure Implementation : Link List

This program demonstrates the link list implementation in Java. The Insert, Delete, Search Operation has been implemented.

Find the Java Code below :

import java.util.Scanner;

/*
* This class demonstrates Link List Implementation in java with Add/Delete/Search Operations.
* @author : Madan Gopal Singh
* @version : 1.0
* @date : 13th March, 2013
*/
public class LinkList {

public int id;
public String info;
public LinkList next;

public LinkList(){
}

public LinkList(LinkList l ){
this.next=l;
}

public LinkList(int id,String info) {
this.id=id;
this.info=info;
this.next=null;
}

/**
* This method add a new node into the link list at last.
* @param startNode The Starting node of link list.
* @param nodeToBeInserted The node which you want to insert
* @return void.
*/
public static void addNewNodeAtLast(LinkList startNode,LinkList nodeToBeInserted){
LinkList lastNode = LinkList.getLastNode(startNode);
LinkList.addNewNodeAtSpecificPosition(lastNode, nodeToBeInserted);
}

/**
* This method add a new node into the link list at start.
* @param startNode The Starting node of link list.
* @param nodeToBeInserted The node which you want to insert
* @return void.
*/
public static LinkList addNewNodeAtFirst(LinkList startNode,LinkList nodeToBeInserted){
nodeToBeInserted.next = startNode;
return nodeToBeInserted;
}

/**
* This method add a new node into the link list at start.
* @param specificPositionedNode The Specific Node of which you want to insert.
* @param nodeToBeInserted The node which you want to insert
* @return LinkList Link list with New Starting Node.
*/
public static void addNewNodeAtSpecificPosition(LinkList specificPositionedNode,LinkList nodeToBeInserted){
LinkList tempNode = null;
tempNode = specificPositionedNode.next;
specificPositionedNode.next=nodeToBeInserted;
nodeToBeInserted.next = tempNode;
}

/**
* This method removes the node from last.
* @param startNode Remove the last node of link list.
* @return void.
*/
public static void removeNodeFromLast(LinkList startNode){
LinkList secondLastNode = null;
if(startNode!=null){
while(startNode.next!=null){
System.out.println("Node Id : "+startNode.id+", Node Info : "+startNode.info);
secondLastNode = startNode;
startNode=startNode.next;
}
secondLastNode.next=null;
}else{
System.out.println("No Node in List Please add first");
}
}

/**
* This method removes a node from start of list.
* @param startNode Remove the start node of link list.
* @return LinkList.
*/
public static LinkList removeNodeFromFirst(LinkList startNode){
LinkList tempNode = startNode.next;
return tempNode;
}

/**
* This method removes a node from specific position of list.
* @param startNode start node of link list.
* @param nodeToBeRemovedId Node id of which you want to remove
* @return void.
*/
public static void removeNodeFromSpecificPosition(LinkList startNode,int nodeToBeRemovedId){
LinkList tempNode = null;
LinkList previousNode = null;
if(startNode!=null){
previousNode=startNode;
while(startNode.next!=null){
if(startNode.id==nodeToBeRemovedId){
tempNode = startNode.next;
previousNode.next = tempNode;
}
previousNode = startNode;
startNode=startNode.next;
}
}else{
System.out.println("No Node in List Please add first");
}
}

/**
* This method traverse the whole list.
* @param startNode start node of link list.
* @return void.
*/
public static void traverseLinkList(LinkList startNode){
if(startNode!=null){
while(startNode.next!=null){
System.out.println("Node Id : "+startNode.id+", Node Info : "+startNode.info);
startNode=startNode.next;
}
}else{
System.out.println("No Node in List Please add first");
}
}

/**
* This method search a specific node in the list.
* @param startNode start node of link list.
* @param searchNodeId search information of node which you want to search
* @return void.
*/
public static LinkList traverseLinkListSpecificNode(LinkList startNode,int searchNodeId){
LinkList positionedNode = null;
if(startNode!=null){
while(startNode.next!=null){
if(startNode.id==searchNodeId){
System.out.println("Node found at position "+startNode.id);
positionedNode = startNode;
break;
}
startNode=startNode.next;
}
}else{
System.out.println("No Node in List Please add first");
}
return positionedNode;
}

/**
* This method returns the last node of the list.
* @param startNode start node of link list.
* @return void.
*/
public static LinkList getLastNode(LinkList startNode){
LinkList lastNode = null;
while(startNode.next!=null){
lastNode = startNode;
startNode = startNode.next;
}
System.out.println("Last Node Id : "+lastNode.id);
return lastNode;
}

/**
* This method returns the last node of the list.
* @param args command line argument list
* @return void.
*/
public static void main(String[] args){
int userOperation = 0,nodeId=-1, nodePostion= -1;
String nodeInfo = "";
LinkList startNode = new LinkList(nodeId,nodeInfo);
LinkList nodeToBeInserted;
Scanner sc = new Scanner(System.in);
do{
String menuString = "What operation you want to perform?"+
"\n 1. Insert New Node at Last"+
"\n 2. Insert New Node at Start"+
"\n 3. Insert New Node at Specific Position"+
"\n 4. Remove Node from Last"+
"\n 5. Remove Node from Start"+
"\n 6. Remove Node from Specific Position"+
"\n 7. Traverse Whole List"+
"\n 8. Traverse Specific Node in List"+
"\n -1. Exit from Menu"+
"\n Please enter Operation Number : ";
System.out.println(menuString);
userOperation = sc.nextInt();

switch(userOperation){
case 1:
System.out.println("Plese enter node Id : ");
nodeId = sc.nextInt();
System.out.println("Please enter node Info : ");
nodeInfo = sc.next();
nodeToBeInserted = new LinkList(nodeId, nodeInfo);
LinkList.addNewNodeAtLast(startNode, nodeToBeInserted);
break;
case 2:
System.out.println("Plese enter node Id : ");
nodeId = sc.nextInt();
System.out.println("Please enter node Info : ");
nodeInfo = sc.next();
nodeToBeInserted = new LinkList(nodeId, nodeInfo);
startNode = LinkList.addNewNodeAtFirst(startNode, nodeToBeInserted);
break;
case 3:
System.out.println("At which position you want to insert new node. Enter Position?");
nodePostion = sc.nextInt();
LinkList specificPositionedNode = LinkList.traverseLinkListSpecificNode(startNode, nodePostion);
System.out.println("Plese enter node Id : ");
nodeId = sc.nextInt();
System.out.println("Please enter node Info : ");
nodeInfo = sc.next();
nodeToBeInserted = new LinkList(nodeId, nodeInfo);
LinkList.addNewNodeAtSpecificPosition(specificPositionedNode,nodeToBeInserted);
break;
case 4:
LinkList.removeNodeFromLast(startNode);
System.out.println("Last Node has been removed");
break;
case 5:
startNode = LinkList.removeNodeFromFirst(startNode);
System.out.println("Starting Node has been removed");
break;
case 6:
System.out.println("At which position you want to delete node. Enter Position?");
nodePostion = sc.nextInt();
LinkList.removeNodeFromSpecificPosition(startNode, nodePostion);
break;
case 7:
LinkList.traverseLinkList(startNode);
break;
case 8:
System.out.println("Please enter node Id to Search : ");
nodePostion = sc.nextInt();
LinkList specificNode = LinkList.traverseLinkListSpecificNode(startNode,nodePostion);
break;
case -1:
System.out.println("Exit Application");
System.exit(0);
default : System.out.println("Exit from System");
}
}while(userOperation!=-1);
}
}

 

Any suggestion is invited if any.

Technology – The introduction and impacts

Hello Guys,

Technology in today’s era is really most important part of Human beings life. today we are not complete with technology. Technology has certain impacts on our society.

 

Technology is really important for youths, children and old peoples because in each step today the technology has its important role.

 

By looking into all factors today i have also started to write blogs for technology and its important impacts on lives so that we can aware more about it in future.

 

You can stay touch with new thoughts and blogs weekly basis 

 

Thanks