Friday, December 10, 2010
Java:Passing object means passing address, but not for primitive
Posted by Sajjad at 12:25 am 0 comments
Labels: Java
Tuesday, September 21, 2010
DSA: Queue Implementation Using Arrays
class Qu
{
int a[],front=-1,rear=-1,max,count=0;
Qu(int size)
{
a=new int[size];
max=size;
}
void enQ(int x)
{
if(isFull())
{
System.out.println("Q is Full");
}
else if(isEmpty())
{
front++;
rear++;
a[rear]=x;
}
else
{
a[rear]=x;
rear++;
}
}
public void dQ()
{
int item;
if(isEmpty())
{
System.out.println("Q is Empty");
}
else
{
System.out.println("Element \t "+a[front]+"\t deleted from Q");
front++;
}
if(front==rear)
{
front=-1;
rear=-1;
}
}
public boolean isEmpty()
{
if(((front==-1)&&(rear==-1)))
return true;
else
return false;
}
public boolean isFull()
{
if(rear==max)
{
System.out.println("Rear"+rear+" Max \t"+max);
return true;
}
else
return false;
}
public void display()
{
System.out.println("Elements are");
for(int i=front;i
{
System.out.print("\t"+a[i]);
}
System.out.println("");
}
}
Posted by Sajjad at 11:07 pm 0 comments
DSA:Depth First Search
package javaapplication8;
import java.io.*;
class graph
{
int a[][];
int f[];
int vtx;
graph(int v)
{
vtx=v;
f=new int[vtx+1];
a=new int[vtx+1][vtx+1];
}
void getdata()throws Exception
{
int i,j;
for(i=1;i<(vtx+1);i++)
{
for(j=1;j
{
System.out.println(i+"->"+j);
System.out.print("\t 0-->no\t 1-->yes\n");
InputStreamReader isrx=new InputStreamReader(System.in);
BufferedReader brx=new BufferedReader(isrx);
int bx=Integer.parseInt(brx.readLine());
a[i][j]=bx;
}
}
}
void visited(int s)
{
f[s]=1;
}
void dft(int s)
{
visited(s);
System.out.println(s+"");
for(int i=s,j=1;j<(vtx+1);j++)
{
if(a[i][j]==1)
{
if(f[j]==0)
{
dft(j);
}
}
}
}
void disgraph()
{
for(int i=1;i<(vtx+1);i++)
{ for(int j=1;j<(vtx+1);j++)
{ System.out.print(a[i][j]+"\t ");
}
System.out.println("");
}
}
}
class javaapplication8
{
public static void main(String[] args)throws Exception
{ int h;
System.out.println("enter the number of vertex");
InputStreamReader isr2=new InputStreamReader(System.in);
BufferedReader br2=new BufferedReader(isr2);
h=Integer.parseInt(br2.readLine());
graph g=new graph(h);
g.getdata();
g.disgraph();
System.out.println ("........DFT.............");
g.dft(1);
}
}
DSA :Queue implementation using Linked List
package javaapplication7;
import java.io.*;
import java.lang.*;
class node
{ int data;
node next;
node(int n)throws Exception
{
next=null;
data=n;
}
void display()throws Exception
{
System.out.println(data);
}
}
class Qu
{
node head=null,tail=null;
void enQ(int dd)throws Exception
{
node n1=new node(dd);
if(head==null)
{
head=n1;
tail=n1;
}
else
{
tail.next=n1;
tail=n1;
}
}
node dq()throws Exception
{
node item;
if(head==null)
{
item=null;
System.out.println("Q IS EMPTY");
}
else
{
item=head;
head=head.next;
}
return item;
}
void display()throws Exception
{
System.out.println("Q IS...");
node current=head;
while(current!=null)
{
System.out.println(current.data);
current=current.next;
}
}
}
class javaapplication7
{
public static void main(String[] args)throws Exception
{
int t;
Qu q=new Qu();
do{
System.out.println(" enter your choice \n1.ENQ\n2. DQ \n 3 display \t");
InputStreamReader isr1=new InputStreamReader(System.in);
BufferedReader br1=new BufferedReader(isr1);
int op=Integer.parseInt(br1.readLine());
switch(op)
{
case 1:System.out.println("enter the element to be EN Q");
InputStreamReader isr2=new InputStreamReader(System.in);
BufferedReader br2=new BufferedReader(isr2);
int j=Integer.parseInt(br2.readLine());
q.enQ(j);
break;
case 2:
node nn= q.dq();
if(nn!=null)
System.out.println(" Element"+nn.data+" is dQ`ed");
break;
case 3:q.display();
break;
default:System.out.println("INVALID OPTION");
}
System.out.println("do you want to continue \n1=>yes \n0=>no");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
t=Integer.parseInt(br.readLine());
}while(t==1);
}
}
Posted by Sajjad at 11:20 am 0 comments
Labels: DSA, Java, Linked List, Queue
DSA :Stack implementation using Linked List
package javaapplication7;
import java.io.*;
import java.lang.*;
class node
{ int data;
node prev,next;
node(int n)throws Exception
{
next=null;
prev=null;
data=n;
}
void display()throws Exception
{
System.out.println(data);
}
}
class stack
{
node top=null;
void push(int dd)throws Exception
{
node n1=new node(dd);
if(top==null)
top=n1;
else
{
top.next=n1;
n1.prev=top;
top=n1;
}
}
node pop()throws Exception
{
node item;
if(top==null)
{
item=top;
System.out.println("STACK IS EMPTY");
}
else if(top.prev==null)
{
item=top;
top=null;
}
else
{
item=top;
top=top.prev;
top.next=null;
}
return item;
}
void display()throws Exception
{
System.out.println("STACK IS...");
node current=top;
while(current!=null)
{
System.out.println(current.data);
current=current.prev;
}
}
}
class javaapplication7
{
public static void main(String[] args)throws Exception
{
int t;
stack s=new stack();
do{
System.out.println(" enter your choice \n1.push\n2.pop\n 3 display \t");
InputStreamReader isr1=new InputStreamReader(System.in);
BufferedReader br1=new BufferedReader(isr1);
int op=Integer.parseInt(br1.readLine());
switch(op)
{
case 1:System.out.println("enter the element to be pushed");
InputStreamReader isr2=new InputStreamReader(System.in);
BufferedReader br2=new BufferedReader(isr2);
int j=Integer.parseInt(br2.readLine());
s.push(j);
break;
case 2:
node nn=s.pop();
if(nn!=null)
System.out.println(nn.data+"is poped out");
break;
case 3:s.display();
break;
default:System.out.println("INVALID OPTION");
}
System.out.println("do you want to continue \n1=>yes \n0=>no");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
t=Integer.parseInt(br.readLine());
}while(t==1);
}
}
Posted by Sajjad at 9:09 am 0 comments
Labels: DSA, Java, Linked List, Stack
Friday, September 17, 2010
Binary Search on unsorted array(Sort with bubble sort)
package binarysearch;
import java.io.*;
class bnsearch
{
int a[],low=0,n=0,flag=0,temp,high=0,key;
int i,mid,j,item;
public void setSize(int max)
{
a=new int[max];
}
public void insert (int item)throws NullPointerException
{
a[n]=item;
n++;
}
public void display()
{
for(i=0;i
System.out.println(a[i]+"\t");
}
public void sort()
{
for(i=0;i
{
for(j=0;j<(n-i-1);j++)
{
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
for(i=0;i
System.out.println(a[i]+"\t");
}
public void search(int key)
{
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==key)
{
flag=1;
break;
}
else if(a[mid]
low=mid+1;
else
high=mid-1;
}
if(flag==1)
{
System.out.println("the element to be found");
System.out.println("the element is in"+(mid+1)+"th position");
}
else
System.out.println("element is not found");
}
}
public class Main
{
public static void main(String[] args)throws IOException
{
int h,n=0,t,k;
System.out.println("enter the number of elements");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
h=Integer.parseInt(br.readLine());
bnsearch b=new bnsearch();
b.setSize(h);
System.out.println("enter the elements");
for(n=0;n
{
InputStreamReader isr1=new InputStreamReader(System.in);
BufferedReader br1=new BufferedReader(isr1);
t=Integer.parseInt(br1.readLine());
b.insert(t);
}
b.sort();
System.out.println("enter the element to be searched");
InputStreamReader isr2=new InputStreamReader(System.in);
BufferedReader br2=new BufferedReader(isr2);
k=Integer.parseInt(br2.readLine());
b.search(k);
b.display();
}
}
Posted by Sajjad at 10:13 pm 0 comments
Tuesday, September 14, 2010
DSA: Quick Sort
class qsort
{
int j,n=0,a[],key,temp;
public qsort(int max)
{
a=new int[max];
}
public void insert(int item)
{
a[n]=item;
n++;
}
public void display()
{int i;
for(i=0;i
{
System.out.print(a[i]+"\t");
}
}
int partition( int left, int right)
{
int i = left, j = right;
int tmp;
int pivot = a[(left + right) / 2];
while (i <= j) {
while (a[i] < pivot)
i++;
while (a[j] > pivot)
j--;
if (i <= j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
};
return i;
}
void quickSort( int left, int right) {
int index = partition( left, right);
if (left < index - 1)
quickSort( left, index - 1);
if (index < right)
quickSort( index, right);
}
}
Posted by Sajjad at 5:18 pm 0 comments
DSA:Insertion Sort
class insertionsort
{
int j,n=0,a[],key;
public insertionsort(int max)
{
a=new int[max];
}
public void insert(int item)
{
a[n]=item;
n++;
// System.out.println("Element"+a[n-1]+"INserted");
}
public void display()
{int i;
for(i=0;i
{
System.out.print(a[i]+"\t");
}
}
public void sort()
{
int k,i;
for(i=0;i
{
key=a[i];
for(j=(i-1);(j>-1)&&(key
{
a[j+1]=a[j];
}
a[j+1]=key;
}
}
}
Posted by Sajjad at 2:14 pm 0 comments
DSA:Bubble Sort
class bubblesort
{
int i,j,n=0,a[];
public bubblesort(int max)
{
a=new int[max];
}
public void insert(int item)
{
a[n]=item;
n++;
}
public void display()
{
for(i=0;i
System.out.print(a[i]+"\t");
}
public void sort()
{
for(i=0;i
{
for(j=0;j<(n-i-1);j++)
{
if(a[j]>a[j+1])
{
int temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
}
}
Posted by Sajjad at 12:36 pm 0 comments
DSA:Binary Search
class binarysearch
{
int a[];
int i,j,n=0,mid,low=0,high,item;
public binarysearch(int max)
{
a=new int[max];
n=0;
}
public void insert(int item)
{
a[n]=item;
n++;
}
public void display()
{
for(i=0;i
System.out.print(a[i]+"\t");
}
public void binsearch(int key)
{
int flag=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==key)
{
flag=1;
break;
}
else if(a[mid]
low=mid+1;
else
high=mid-1;
}
if(flag==1)
{
System.out.print("the element is found");
System.out.print("the element is"+(mid+1)+"th position");
}
else
System.out.print("the element is not found");
}
}
Posted by Sajjad at 10:25 am 0 comments
Monday, September 13, 2010
DSA:circular queue
class circularqueue
{
int rear=-1,front=-1,len;
int a[]=new int[50],val,item;
circularqueue(int w)
{
len=w;
}
public void insert(int item)
{
if(front==thenext(rear))
{
System.out.println("Q is fulll");
}
else if(front==-1)
{ front=0;
rear=0;
a[rear]=item;
}
else
{
rear=thenext(rear+1);
a[rear]=item;
System.out.println("inserted element is"+ a[rear]);
}
}
public void delete()
{
if(front==rear)
{
front=-1;
rear=-1;
System.out.println("queue is empty");
}
else
{ val=a[front];
front=thenext(front);
System.out.print("deleted element is:"+val);
}
}
public int thenext(int val)
{
int next=(val+1)%len;
return next;
}
public void display()
{
if(front==-1&&rear==-1)
System.out.println("queue is empty");
else
{
System.out.println("QUEUE contains....");
int i=front;
do
{
System.out.println(a[i]+"\t");
i=thenext(i);
}while(i!=thenext(rear)) ;
}
}
}
Posted by Sajjad at 10:39 pm 0 comments
Wednesday, July 14, 2010
Plot a dynamic Graph using Jquery and Google Chart API
Source Code
Source Code text.php
session_start();
function insert_data($val)
{
for($i=0;$i<100;$i++)
{
if(!isset($_SESSION[v][$i]))
{
for($k=0;$k<100;$k++)
$_SESSION[v][$k]=mt_rand(0,120);
}
else
$_SESSION[v][$i]=$_SESSION[v][$i+1];
if($i!=0)
$str.=",";
$str.=$_SESSION[v][$i];
}
$_SESSION[v][100]=$val;
$str.=",$val";
return $str;
}
//print_r($_SESSION[v]);
$k=insert_data(date("i")+date("s")+mt_rand(10,22)-mt_rand(0,8));
?>
HTML
U Will Get source code in
http://csajjad.com/eg/gr_dynmc.php
Posted by Sajjad at 4:03 pm 0 comments
Labels: chart, google API, javascript, php
Thursday, July 08, 2010
faces-config entry for View Parameter
(navigation-case)
(redirect)
(from-outcome)(/from-outcome)
(to-view-id)(/to-view-id)
(view-param)
(name)(/name)
(value)(/value)
(/view-param)
(/redirect)
(/navigation-case)
replace)with > and ( with <
Posted by Sajjad at 6:44 am 0 comments
Labels: JSF, View Parameter
Tuesday, July 06, 2010
Monday, June 14, 2010
Error:java.lang.String cannot be cast to javax.faces.model.SelectItem
Problem
<;f:selectItem itemLabel="Male" value="male">
Solution
<;f:selectItem itemLabel="Male" itemValue="male">
<: is used as an escape from html rendering correct portion is
Posted by Sajjad at 6:02 am 0 comments
Labels: JSF
Monday, May 03, 2010
Lighttpd web server setup custom PHP.INI file for each user or domain
http://www.cyberciti.biz/tips/custom-phpini-file-for-each-domain-user.html
Posted by Sajjad at 12:40 pm 0 comments
Labels: lighthttpd, php
Sunday, May 02, 2010
test your WSDL
http://www.soapclient.com/soaptest.html
Posted by Sajjad at 4:07 pm 0 comments
Labels: SOAP, webservice
SOAP client tutorial
http://search.cpan.org/~mkutter/SOAP-WSDL-2.00.05/lib/SOAP/WSDL/Client.pm
Posted by Sajjad at 4:04 pm 0 comments
Labels: php, SOAP, webservice
Saturday, May 01, 2010
Friday, April 30, 2010
WSDL Resources
WSDL tutorial
http://www.w3schools.com/wsdl/
SOAP tutorial
http://www.w3schools.com/soap/
Using SOAP in WSDL Application
http://www.ibm.com/
Developing SOAP client in ASP.net
http://bytes.com/topic/
http://www.velocityreviews.
http://blogs.msdn.com/
Sample Web services to develop applications
http://webservices.seekda.com
http://www.webservicex.com/
Posted by Sajjad at 3:08 am 0 comments
Tuesday, January 19, 2010
Making charts with php+google chart API
http://luddep.se/notebook/2008/04/13/charts-php-and-google-charts-api/
Posted by Sajjad at 1:40 pm 0 comments
Labels: chart, google API, php