Author Archives: qainterviews

About qainterviews

Software Geek,QA Expert,Blogger

Insertion Sort Java

package test; public class InsertionSort { public int[] sort(int []arr) { int key,i; for(int j=1;j<arr.length;j++) { key=arr[j]; i=j-1; while(i>=0 && arr[i]>key) { arr[i+1]=arr[i]; arr[i]=key; i–; } } return arr; } public static void main(String[] args) { // TODO Auto-generated method … Continue reading

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

Java GC

https://www.journaldev.com/2856/java-jvm-memory-model-memory-management-in-java#memory-management-in-java-8211-young-generation

Posted in Uncategorized | Leave a comment

Number Complement

https://leetcode.com/problems/number-complement/description/ public class Solution { public int findComplement(int num) { String binary=Integer.toBinaryString(num); char []converted=binary.toCharArray(); for(int i=0;i<converted.length;i++) { if(converted[i]==’0′) { converted[i]=’1′; } else { converted[i]=’0′; } } return Integer.parseInt(String.valueOf(converted),2); } public static void main(String[] args) { Solution i1=new Solution(); System.out.println(“Binary value: … Continue reading

Posted in Uncategorized | Leave a comment

Remove Duplicates from an Array

package test; import java.util.HashSet; import java.util.Set; import org.testng.annotations.Test; public class ArrayDuplicate { @Test public void testRemoveArrayDuplicates() { int a[]= {1,2,1,3,4,2,5}; Set<Integer> set=new HashSet<Integer>(); for(int i=0;i<a.length;i++) { set.add(a[i]); } System.out.println(set); } }

Posted in Uncategorized | Leave a comment

Implement Queue in Java

package test; import org.testng.annotations.Test; class QNodes { QNodes front,rear,next; int data; public QNodes(int data) { this.data=data; } } public class Queue { QNodes front; QNodes rear; public void enqueue(int data) { if(front==null) { rear=new QNodes(data); front=rear; } else { rear.next=new … Continue reading

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

Implement Stack Java

package test; import org.testng.annotations.Test; class Nodes { int data; Nodes next; Nodes prev; public Nodes(int data) { this.data=data; } } public class Stack { Nodes top; void push(int data) { //Nodes temp ; Nodes temp=new Nodes(data); temp.next=top; top=temp; } //end … Continue reading

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

LinkedList Java

class Node { int data; Node next; public Node(int data) { this.data=data; } } public class TestLL{ @Test public void testLinkedList() { Node n1=new Node(10); Node n2=new Node(20); n1.next=n2; Node temp; temp=n1; //Display LinkedList while(temp!=null) { System.out.println(temp.data); temp=temp.next; } //Deleting … Continue reading

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