10.15.08

Want to test ur testing skills..

Posted in Testing at 6:07 pm by vchaithanya

go throgh this link

http://www.testinggeek.com/testometer.asp

and try filling with answers and test ur ability of testing.

Different Sorting algorithms code

Posted in Sorting&Searching at 5:56 pm by vchaithanya

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, 1, 2, 2, 2, 3, 3, 3, 2, 1, 3, 2 };
            Console.WriteLine(“before”);
            PrintArray(a);
           // QuickSort(a, 0, a.Length-1);
           // SelectionSort(a);
           // BubbleSort(a);
            InsertionSort(a);
            Console.WriteLine(“After”);
            PrintArray(a);
        }
        /*
         *
         */
        static void QuickSort(int[] a, int start, int end)
        {
            if (start > end)
            {
                return;
            }
            //treat last element as pivot element, so will send ‘end’ as pivot index
            int pIndex = Partition(a, start, end, end);
            QuickSort(a, start, pIndex – 1);
            QuickSort(a, pIndex + 1, end);
           
        }
        //Take the pivot element using partition index(p) and exchange pivot with last element
        static int Partition(int[] a, int start, int end, int p)
        {
            int pivot = a[p];
            Exchange(ref a[end], ref a[p]);
            int sIndex = start;
            for (; start <= end – 1; start++)
            {
                if (a[start] <= pivot)
                {
                    Exchange(ref a[start], ref a[sIndex]);
                    sIndex++;
                }
            }
           Exchange(ref a[sIndex], ref a[end]);

           PrintArray(a);
           return sIndex;
        }
        static void Exchange(ref int a, ref int b)
        {
            int tmp = a;
            a = b;
            b = tmp;
        }

        static void PrintArray(int[] a)
        {
            foreach (int i in a)
            {
                Console.Write(i + ” “);
            }
            Console.WriteLine(“”);
        }
        //select a min element and place it in first position
        static void SelectionSort(int[] a)
        {
            for (int i = 1; i < a.Length; i++)
            {
                int minIndex = i-1;
           
                for (int j = i; j < a.Length; j++)
                {
                    if (a[minIndex] > a[j])
                    {
                        minIndex = j;
                    }
                }
                Exchange(ref a[i - 1], ref a[minIndex]);

                PrintArray(a);
            }
        }
        // Exchanging the elements until there are no swaps.
        static void BubbleSort(int[] a)
        {
            bool swap;
            do
            {
                swap = false;
                for (int i = 0; i < a.Length-1; i++)
                {
                    if (a[i] > a[i + 1])
                    {
                        Exchange(ref a[i], ref a[i + 1]);
                        swap = true;
                    }
                }
                Console.Write(swap + “  “);
                PrintArray(a);
            } while (swap == true);
        }
        //take an element to insert that element in correct position below that index
        // so all the elements before that index will always in sorted order
        //move the index one by one and insert that in correct position below in that index.
        static void InsertionSort(int[] a)
        {
            for (int i = 1; i < a.Length; i++)
            {
                int val = a[i];
                int j = i – 1;
                while (j>= 0 && a[j] > val)
                {
                    a[j + 1] = a[j];
                    j–;
                }
                Exchange(ref a[j + 1], ref val);
                PrintArray(a);
            }
        }
    }
}

10.07.08

SanJuan Island Trip..

Posted in my holiday trips at 12:20 am by vchaithanya

This is my first island trip. SanJuan Islands, they came into WA state but they are in the border of Canada(British Columbia). We started at 8am at home. Its 2hrs drive from our place and 1hr on ferry and Its also my first Ferry trip. I never forget this trip.

In the map it looks like a small Isaland, ofcourse it is. For us It tooks around 6hrs to cover the entire island. Its famous for camping, kayaking, beaches, whale watching, boating, fishing. And there are apple trees, wine yards and lavendar farms. These lavender flowers they used in making scents. And old building resembling british culture. there are lot of beaches. Its also a very good place for camping.

10.06.08

Testing Our implementation of LinkedList…

Posted in DataStructures at 11:07 pm by vchaithanya

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 = (Iterator)list.iterator();itr.hasNext();){
   System.out.println(itr.next());
  }
  list.add(“9″); */
  
 }
}

Implementing Linked List…

Posted in DataStructures at 10:10 pm by vchaithanya

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;
  }
  next.link = node;
 
 }
 public void addFirst(int data){
  Node node = new Node(data, head);
  head = node;
 }
 public void print()
 {
  Node next = head;
  for(;next!=null;next=next.link){
   System.out.println(next);
  }
 }
 //reversing a linked list
 public void reverse()
 {
  Node prev = null;
  while(head!=null){
   Node tmp = head;
   head = head.link;
   tmp.link = prev;
   prev = tmp;
  }
  head = prev;
 }
 

}
class Node {
 int data;
 Node link;
 public Node() {
  data = 0;
  link = null;
 }
 public Node(int data, Node link) {
  this.data = data;
  this.link = link;
 }
 public String toString(){
  return(“data value is :”+data);
 }
}

Previous page · Next page