Category Archives: java

Different Sorting algorithms code

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample1 {     class SortingAlgorithms     {         static void Main()         {             int[] a = { 23, 45, 65, 23, 12, 77 };             //int[] a = { 1, … Continue reading

Posted in Sorting&Searching | Leave a comment

Testing Our implementation of LinkedList…

package com.test.ds; import java.util.*; public class LinkedListTest {  public static void main(String[] arg){   CLinkedList clist = new CLinkedList();   clist.addFirst(1);   clist.addFirst(2);   clist.addFirst(3);      clist.addFirst(4);      clist.addLast(5);   clist.addLast(6);   clist.addLast(7);   clist.print();   clist.reverse();   clist.print();   /*ArrayList list = new ArrayList();   list.add(“1″);   list.add(“5″);   list.add(“3″);   for(Iterator itr … Continue reading

Posted in DataStructures | Leave a comment

Implementing Linked List…

package com.test.ds; public class CLinkedList {  Node head;  CLinkedList(){  }  public void addLast(int data)  {   Node node = new Node(data, null);   if(head == null){    head = node;    return;   }   Node next = head;   while(next.link != null) {    next = next.link; … Continue reading

Posted in DataStructures | Leave a comment

Different operations of BinaryTree…

//depth of a binary Tree /* int depth(Root T) { if(T == NULL) return 0; d1 = depth(T -> left); d2 = depth(T -> right); return (max(d1,d2) + 1); } */ // Print binary tree /* Void print(Tree t){ If(t==null) … Continue reading

Posted in DataStructures | 1 Comment

Optimized String Reverse Algorithm…

package com.test.stringOps; public class StringReverse { public static String reverse(String str) { if (str == null || str.length() == 0) { return str; } else { StringBuilder bul = new StringBuilder(str); for(int i=0,j=bul.length()-1;i char c=bul.charAt(i); bul.setCharAt(i, bul.charAt(j)); bul.setCharAt(j, c); } … Continue reading

Posted in Strings | Leave a comment