tag:blogger.com,1999:blog-11573181025333041182024-03-21T18:55:26.996+05:30Source Codes JAVA & C++We are the youths,we have an immense power to direct our future..so myself as one among you who has so many dreams don't wanna just dream but make it real!So an awakening call to the youths..please join hands with me to live for others and JUST GO FOR IT!! Believe me its fun!!Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.comBlogger56125tag:blogger.com,1999:blog-1157318102533304118.post-40854900587662588282013-08-23T21:10:00.001+05:302013-08-23T21:19:15.389+05:3056. HAMMIMG CODE <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import java.util.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class Hamming<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">static Scanner sc = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int data[];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int parity[];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int code[];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int a[];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">static int n,i,p;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">void input()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("Enter the no.of data
bits:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">n=sc.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">data=new int[n];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("Enter the data
bits:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=n-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">data[i]=sc.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(n==2 || n==3 || n==4)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p=3;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(n==5 || n==6 || n==7 || n==8 || n==9 || n==10
|| n==11)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p=4;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nNo.of parity bits
required = "+p);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">parity=new int[p];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code=new int[n+p];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">a=new int[n+p];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">} void calculate()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=0;i<p;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
parity[i]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int j=0; int d=0; int x=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=0;i<n+p;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(i==(Math.pow(2,x)-1))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">a[i]=parity[j];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">j++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">x++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">a[i]=data[d];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">d++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=0;i<n+p;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
code[i]=a[i];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}
if((code[0]+code[2]+code[4]+code[6])%2==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[0]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[0]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if((code[1]+code[2]+code[5]+code[6])%2==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[1]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[1]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if((code[3]+code[4]+code[5]+code[6])%2==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[3]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[3]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nThe Hamming Code is
:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=(n+p)-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
System.out.print(code[i]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">} void
errorcheck()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nEnter the Corrupted
Hamming Code:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=(n+p)-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
code[i]=sc.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nThe Corrupted Hamming
Code:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=(n+p)-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
System.out.print(code[i]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">parity[0]=code[0];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">parity[1]=code[1];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">parity[2]=code[3];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if((((code[2]+code[4]+code[6])%2==0 &&
parity[0]==0)||(((code[2]+code[4]+code[6])%2)!=0) && parity[0]==1))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
parity[0]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
parity[0]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if((((code[2]+code[5]+code[6])%2==0 &&
parity[1]==0)||(((code[2]+code[5]+code[6])%2)!=0) && parity[1]==1))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parity[1]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parity[1]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if((((code[4]+code[5]+code[6])%2==0 && parity[2]==0)||(((code[4]+code[5]+code[6])%2)!=0)
&& parity[2]==1 ))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parity[2]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parity[2]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int word=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=2;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
word=word+(parity[i]*(int)Math.pow(2,i)); <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> } if(word==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nThe data code is
correctly received"); <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nThe bit no.
"+word+" is wrongly received");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(code[word-1]==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[word-1]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">code[word-1]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">System.out.println("\nThe Corrected Hamming
Code:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=(n+p)-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{ System.out.print(code[i]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}
System.out.println();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public static void main(String arg[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{ Hamming
h=new Hamming();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">h.input();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">h.calculate();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">h.errorcheck();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the no.of data bits:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">4<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the data bits:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">No. of parity bits required = 3<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Hamming Code is :<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1010101<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Corrupted Hamming Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Corrupted Hamming Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1010100<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The bit no. 1 is wrongly received<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Corrected Hamming Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1010101<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br />
<div class="MsoNormal" style="background: white; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: #222222; font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Need the code??<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: #222222; font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Download Link= <a href="https://www.dropbox.com/s/umlbpia77como3k/Hamming.docx">https://www.dropbox.com/s/umlbpia77como3k/Hamming.docx</a></span></div>
</div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-83548425590863553912013-08-23T21:02:00.001+05:302013-08-23T21:02:18.381+05:3055. FRAMING TECHNIQUES<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import java.io.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class Framing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
static void main(String args[]) throws IOException<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
data;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter
the Data Stream: ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> data=br.readLine();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
str;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
select;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nThe
various Framing techniques are:\n1) Character Count\n2) Byte Stuffing\n3) Bit
Stuffing\n4) Physical Data Violation\n\nEnter the number for the corresponding
Framing technique: ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> str=br.readLine();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> select=Integer.parseInt(str);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(select)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
1: System.out.print("\nThe Frame after Processing is: "+CC(data));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
2: System.out.print("\nEnter the Flag Stream: ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
flag;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> flag=br.readLine();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nThe
Frame after processing: "+Byte(data,flag));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
3: flag="01111110";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nThe
Flag Stream is: "+flag);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\n\nThe
Frame after processing: "+Bit(data,flag));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
4: System.out.print("\nThe Frame after processing: "+PDV(data));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
static String CC(String input)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
len=input.length();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
head=""+len;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
output=head+input;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
output;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
static String Byte(String input,String flag)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
len=input.length();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
lenf=flag.length();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> char
na[]=new char [2*len];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
ni=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
fromindex=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=0;i<len;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> fromindex=input.indexOf(flag,i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(fromindex==i)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]='e';<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
j=0;j<lenf;j++,i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]=flag.charAt(j);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else
if(i<fromindex)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
l=i;l<fromindex;l++,i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]=input.charAt(l);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else
if(fromindex==-1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
k=i;k<len;k++,i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]=input.charAt(k);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> i=i-1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
output=new String (na,0,ni);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
flag+" "+output+" "+flag;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
static String Bit(String input,String flag)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
count=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
len=input.length();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
maxs=len/5;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
ni=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> char
na[]=new char [len+maxs];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=0;i<len;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(input.charAt(i)=='1')<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> count++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(count==5)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> count=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]=input.charAt(i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]='0';<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> { <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> count=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]=input.charAt(i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
output=new String (na,0,ni);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
flag+" "+output+" "+flag;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
static String PDV(String input)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
len=input.length();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> char
na[]=new char [len];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
ni=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=0;i<len;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(input.charAt(i)=='0')<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]='L';<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> na[ni]='H';<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ni++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> String
output=new String (na);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
output;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">OUTPUT:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Data Stream: 0110<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The various Framing techniques are:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1) Character Count<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">2) Byte Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">3) Bit Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">4) Physical Data Violation<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the number for the corresponding Framing
technique: 1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Frame after Processing is: 40110<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Data Stream: 111111100011001010111111<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The various Framing techniques are:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1) Character Count<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">2) Byte Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">3) Bit Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">4) Physical Data Violation<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the number for the corresponding Framing
technique: 2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Flag Stream: 111<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Frame after processing: 111
e111e111100011001010e111e111 111<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Data Stream: 1111111111111111<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The various Framing techniques are:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1) Character Count<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">2) Byte Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">3) Bit Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">4) Physical Data Violation<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the number for the corresponding Framing
technique: 3<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Flag Stream is: 01111110<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Frame after processing: 01111110
1111101111101111101 01111110<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the Data Stream: 1111100<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The various Framing techniques are:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">1) Character Count<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">2) Byte Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">3) Bit Stuffing<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">4) Physical Data Violation<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Enter the number for the corresponding Framing
technique: 4<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">The Frame after processing: HHHHHLL<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: #222222; font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Need the code??<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0cm;">
<span style="color: #222222; font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: Arial; mso-fareast-font-family: "Times New Roman"; mso-fareast-language: EN-IN;">Download Link= https://www.dropbox.com/s/t099t9vrdromflb/Framing.docx<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">
</span></div>
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-83366856465495286732013-06-17T12:23:00.001+05:302013-06-17T12:23:31.422+05:3054. SEPARATING POSITIVE & NEGATIVE NUMBERS<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SI,1100<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MOV CX,0A<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MOV AL,00<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">L2:
MOV BX,[SI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ADD BX,00H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JS L1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> INC SI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> INC AL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DEC CX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JNZ L2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JMP L3<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">L1:
INC SI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> INC AH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DEC CX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JNZ L2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">L3:
HLT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/fnwc5yqf364k52b/seperating%20positive%20and%20negative%20nos.docx?m">https://www.dropbox.com/s/fnwc5yqf364k52b/seperating%20positive%20and%20negative%20nos.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-6223616933579235682013-06-17T12:21:00.002+05:302013-06-17T12:21:45.327+05:3053. MATRIX MULTIPLICATION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SI,1000<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MOV BP,1020<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MOV DI,1050<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">L2: MOV CX,00<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">L1: MOV AL,[SI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MOV BL,[BP]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> MUL BL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ADD CX,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ADD BP,03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> INC SI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> CMP BP,1029<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JB L1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> SUB SI,03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> SUB BP,08<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ADD DI,02<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> CMP BP,1023<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JB L2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ADD SI,03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> SUB BP,03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> CMP DI,1051<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> JB L2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">HLT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/md3fqu4tgaxd09r/matrix%20multiply.docx">https://www.dropbox.com/s/md3fqu4tgaxd09r/matrix%20multiply.docx</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-83539801934049588262013-06-17T12:20:00.001+05:302013-06-17T12:20:15.423+05:3052. CODE CONVERSION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASCII
ADJUSTMENT INSTRUCTIONS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,31H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,39H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AAA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,3030H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BL,9<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,0702H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AAD
<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIV
BL <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AL,5 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CL,5 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MUL
CL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AAM
<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,3030H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,38H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SUB
AX,31H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AAS
<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AX,3030H
<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BINARY
TO BCD CONVERSION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BIN
DW 01A9H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BCD
DB 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,BIN<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CL,64H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIV
CL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BCD+1,AL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AL,AH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,00H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CL,0AH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIV
CL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CL,04<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ROR
AL,CL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AL,AH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Input:
binary--------01A9<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Output:
bcd------------425<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BCD
TO BINARY CONVERSION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BCD
DW 27H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">BIN
DW ?<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,BCD<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AND
AX,07H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,BCD<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">AND
AX,0F0H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CX,0AH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MUL
CX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,BX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BIN,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Input:
BCD-------------27<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Output:------------------1B<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/z6tbcbufoholw4g/code%20conversions%20in%208086.docx?m">https://www.dropbox.com/s/z6tbcbufoholw4g/code%20conversions%20in%208086.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-58839000592651169172013-06-17T12:18:00.002+05:302013-06-17T12:18:54.523+05:3051. BLOCK TRANSFER IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">X
DB 01H,02H,03H,04H,05H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:MOV
AX,DATA <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CX,05H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,X+04 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
DI,X+04+03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">UP:
MOV BL,[SI] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
[DI],BL <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DEC
SI <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DEC
DI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DEC
CX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">JNZ
UP<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/q86hxddmyw7jbx1/block%20transfer%20in%208086.docx?m">https://www.dropbox.com/s/q86hxddmyw7jbx1/block%20transfer%20in%208086.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-44952353118219299842013-06-17T12:17:00.001+05:302013-06-17T12:17:33.363+05:3050. BLOCK INTERCHANGE IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">X
DB 01H,02H,03H,04H,05H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Y
DB 11H,12H,13H,14H,15H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:MOV
AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CX,05H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,X <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
DI,Y <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">UP:
MOV BL,[SI] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AL,[DI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
[SI],AL <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
[DI],BL <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
SI <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
DI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DEC
CX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">JNZ
UP<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/i4m8ng9xurab2zs/block%20interchange%20in%208086.docx?m">https://www.dropbox.com/s/i4m8ng9xurab2zs/block%20interchange%20in%208086.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-37071264467900488092013-06-17T12:16:00.001+05:302013-06-17T12:16:17.417+05:3049. 16 & 32-BIT SUBTRACTION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
SUBTRACTION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM
DW 4567H,2345H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIF
DW 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CLC<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,NUM <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SBB
AX,[SI+2] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DIF,AX
<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT:
4567H,2345H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:2222<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">32-BIT
SUBTRACTION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DW 2345H,6762H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DW 1111H,1111H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIF
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,NUM1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
DI,NUM2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,[DI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SUB
AX,BX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DIF,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
SI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
SI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
DI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
DI<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,[DI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SBB
AX,BX MOV DIF+2,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT:
23456762,-11111111<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:12345651<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT:11111111,-23451234<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:EDCBFEDD<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/uwj1p6e4wh5v07u/32-bit%20subtraction%20in%208086.docx?m">https://www.dropbox.com/s/uwj1p6e4wh5v07u/32-bit%20subtraction%20in%208086.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-52356812574330871762013-06-17T12:14:00.003+05:302013-06-17T12:14:37.880+05:3048. 16-BIT MULTIPLICATION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
MULTIPLICATION FOR UNSIGNED NUMBERS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM
DW 1234H,1234H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">PROD
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,NUM<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,[SI+2]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MUL
BX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
PROD,AX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
PROD+2,DX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT:
Multiplicand- 1234H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Multiplier-
1234H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:
DX-01 4B<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> AX-54 90<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
MULTIPLICATION FOR SIGNED NUMBERS <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM
DW -2,1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">PROD
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,NUM <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,[SI+2] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">IMUL
BX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
PROD,AX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
PROD+2,DX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT:
Multiplicand- -2,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Multiplier-
1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:
DX – FF FF<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> AX – FF FE<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/9hwez0vvh4sqpeb/16-bit%20multiplication.docx">https://www.dropbox.com/s/9hwez0vvh4sqpeb/16-bit%20multiplication.docx</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-18657793130369197402013-06-17T12:12:00.002+05:302013-06-17T12:12:28.026+05:3047. 16-BIT DIVISION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
DIVISION FOR SIGNED NUMBERS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DW 4567H,2345H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DW 4111H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">QUO
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">REM
DW 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,NUM1 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DX,NUM1+2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIV
NUM2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
QUO,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
REM,DX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: Dividend - 23454567,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Divisor - 4111,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT: AX – 8AC5H (quotient);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DX –
0952H (reminder);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
DIVISION FOR UNSIGNED NUMBERS <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DW 4567H,2345H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DW 4111H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">QUO
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">REM
DW 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,NUM1 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DX,NUM1+2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CWD<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">IDIV
NUM2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
QUO,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
REM,DX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: Dividend - -44444444,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Divisor - 2222,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0UTPUT: AX – FE (quotient);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DX
– FF (reminder)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/jmlja9ufmkomd26/16-bit%20division%20in%208086.docx">https://www.dropbox.com/s/jmlja9ufmkomd26/16-bit%20division%20in%208086.docx</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-3513614865048416022013-06-17T12:10:00.001+05:302013-06-17T12:10:04.840+05:3046. 16 & 32 BIT ADDITION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">16-BIT
ADDITION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM
DW 1234H, 0F234H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SUM
DW 2 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS: CODE, DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,NUM <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
BX,0H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,NUM+2 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">JNC
DOWN <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INC
BX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DOWN:
MOV SUM,AX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SUM+2,BX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT
: 1234H, F234H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT
: 10468H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">32-BIT
ADDITION<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DW 0FFFFH,0FFFFH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DW 1111H,1111H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SUM
DW 4 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">dATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,NUM1<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,NUM2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SUM,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,NUM1+2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADC
AX,NUM2+2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">JNC
DOWN <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SUM+4,01H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DOWN:
MOV SUM+2,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: 0FFFFFFFFH, 011111111H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:
0111111110H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">32-BIT
ADDITION USING DD DIRECTIVE<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DW 12345678H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DW 12345678H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">SUM
DW 3 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:MOV
AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
SI,NUM1 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">LEA
DI,NUM2 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AX,[SI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADD
AX,[DI]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
CX,[SI+2]<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ADC
CX,[DI+2] <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">JNC
DOWN <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SUM+4,01H <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DOWN:MOV
SUM,AX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
SUM+2,CX <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INOUT: 12345678H, 12345678H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT: 2468ACF0H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link=<a href="https://www.dropbox.com/s/su5bn8kvxtms3g4/16%20and%2032%20bit%20addition%20in%208086.docx?m">https://www.dropbox.com/s/su5bn8kvxtms3g4/16%20and%2032%20bit%20addition%20in%208086.docx?m</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-64273524038440365582013-06-17T12:07:00.001+05:302013-06-17T12:07:14.245+05:3045. 8-BIT DIVISION IN 8086<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
</div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">8-BIT
DIVISION FOR UNSIGNED NUMBERS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DB 72H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DB 02H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">QUO
DB 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">REM
DB 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AL,NUM1 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,0H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DIV
NUM2<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
QUO,AL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
REM,AH <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: Dividend - 72H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Divisor - 02 H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0UTPUT: AL - 39H (quotient);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> AX - 00H (reminder);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: Dividend - 55H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Divisor - 04 H,<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0UTPUT: AL - 15H (quotient);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> AX - 01H (reminder);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">8-BIT
DIVISION FOR SIGNED NUMBERS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM1
DB -10<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">NUM2
DB 02<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">QUO
DB 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">REM
DB 1 DUP(0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">DATA
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
SEGMENT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ASSUME
CS:CODE,DS:DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">START:
MOV AX,DATA<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
DS,AX<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AL,NUM1 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CBW<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">IDIV
NUM2 <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
QUO,AL <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
REM,AH <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">MOV
AH,4CH<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INT
21H<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">CODE
ENDS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">END
START<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">INPUT: Dividend - -10<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Divisor - 03<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">0UTPUT: AL – FDH (quotient);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> AX – FF H (reminder) ; Result is in two
complement form<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Download
Link= <a href="https://www.dropbox.com/s/5neou4layyerdt6/8-bit%20division%20in%208086.docx">https://www.dropbox.com/s/5neou4layyerdt6/8-bit%20division%20in%208086.docx</a><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<br />
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-69733559711247174982013-05-22T22:08:00.000+05:302013-05-22T22:08:23.970+05:3044. STACK USING LINKED LIST<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class StackLL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node start=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node top=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node curr=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,num;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> StackLL()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Push(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top.next=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Pop()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Stack is
Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(top==start)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr.next!=top)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top=curr;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("Bottom ->
");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr!=null)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(curr.info + "
-> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Top");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String args[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> StackLL s=new StackLL();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("\n-----------------------------------");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter your
Choice");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("1 :
Push\t2 : Pop\t3 : Display\t4 : Exit");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ch=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter a Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.Push(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.Pop();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.Display();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 4:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> default : continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/1b8j3d74zo12qx6/link%20list%20wid%20stack.docx?m">https://www.dropbox.com/s/1b8j3d74zo12qx6/link%20list%20wid%20stack.docx?m</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-86013202520771612552013-05-22T22:06:00.001+05:302013-05-22T22:06:40.431+05:3043. QUEUE USING LINKED LIST<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class Node<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int info;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node next,prev;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node left,right;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class QueueLL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node start=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node end=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node curr=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,num;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Object obj=new Object();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> QueueLL()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Add(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=end;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Del()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Queue is
Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(start==end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=end;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr.next!=start)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=curr;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=end;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("Back ->
");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr!=null)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(curr.info + "
-> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Front");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String args[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> QueueLL q=new QueueLL();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter your
Choice");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("-------------------------------------");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("1 : Add\t2
: Del\t3 : Display\t4 : Exit");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ch=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter a Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q.Add(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q.Del();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q.Display();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 4:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> default : continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/t38bscte2fi3vp8/link%20list%20wid%20queue.docx?m">https://www.dropbox.com/s/t38bscte2fi3vp8/link%20list%20wid%20queue.docx?m</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-13013130790092466102013-05-22T22:05:00.000+05:302013-05-22T22:05:18.149+05:3042. PRIORITY QUEUE USING HEAP<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<iostream.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<process.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<math.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<iomanip.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<malloc.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">struct
Heap<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
capacity;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
size;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
*element;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">};<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">typedef
struct Heap *pqueue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">pqueue
initialize(int max)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">pqueue
heap;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(max<3)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nPriority
Queue is too Small\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap
= new Heap;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(heap==NULL)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nOut
of Space\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements=new
int[((max+1) * sizeof(int))];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(heap->elements==NULL)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n
Out of Space\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->capacity
= max;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->size=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements[0]=0;
//minData<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return
heap;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
isempty(pqueue heap)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return
(heap->size==0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
isfull(pqueue heap)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return(heap->size==heap->capacity);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">void
insert(int x, pqueue heap)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
i;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(isfull(heap))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nHeap
is Full\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=++heap->size;
heap->elements[i/2] > x; i/=2)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements[i]=heap->elements[i/2];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements[i]=x;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
deletemin(pqueue heap)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
i, child, min, last;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(isempty(heap))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nHeap
is Empty\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return
heap->elements[0];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">min=heap->elements[1];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">last=heap->elements[heap->size--];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=1;
i*2<=heap->size; i=child)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">child
= i*2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(child!=heap->size
&& heap->elements[child+1]<heap->elements[child])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">child++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(last>heap->elements[child])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements[i]=heap->elements[child];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap->elements[i]=last;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">return
min;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">void
main()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
size,ch,ele,child;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">pqueue
heap;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nWorking
with Priority Queues (or) Heaps\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nEnter
the Size of the Heap…”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>size;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">heap
= initialize(size);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">do<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n\t\tMenu\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n1.
Insert”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n2.
Delete”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n3.
Display”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n4.
Exit”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nEnter
Your Choice…”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>ch;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">case
1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nEnter
an Element…”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>ele;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">insert(ele,
heap);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">case
2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">ele=deletemin(heap);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\nDeleted
Element is “<<ele<<endl;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">case
3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
space,level=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
c=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(int
i=1; i<heap->size; i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(int
j=1;j<=level;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(c<=heap->size)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">space=(int)
(heap->size*2)/c;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<setw(space)<<”
“<<heap->elements[c++]<<setw(space)<<” “;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if
(level==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">level=2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else
if (level>=2)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">level=level*2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n”;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">default:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<”\n
Exit “;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}while(ch<4);<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/rw7505iq0kfp054/priority%20queue%20using%20heap.docx">https://www.dropbox.com/s/rw7505iq0kfp054/priority%20queue%20using%20heap.docx</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-29747568340703291482013-05-22T22:03:00.000+05:302013-05-22T22:03:10.123+05:3041. SINGLY LINKED LIST IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class SingleLL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node start=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node end=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node curr=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int num;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> SingleLL()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void AddBeg(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void AddEnd(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end.next=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DelBeg()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Linked
List is Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(start==end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=start.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DelEnd()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Linked List
is Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(start==end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr.next!=end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=curr;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DelEle(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Linked
List is Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node prev=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(end==start &&
start.info==val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else if(start.info==val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=start.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else if(end.info==val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("HEllo");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr.next!=end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=curr;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr.info!=val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> prev=curr;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> prev.next=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> } <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("Start ->
");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr!=null)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(curr.info + "
-> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("End");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Search(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Loop:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
for(curr=start;curr!=null;curr=curr.next)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(curr.info==val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Element
Found");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break Loop;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Element Not
Found");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String args[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> SingleLL sl=new SingleLL();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("-----------------------------------");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter your
Choice");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("1 : Add
Beg 2 : Add End 3 : Del Beg
4 : Del End 5 : Del Ele 6 : Display
7 : Search 8 : Exit");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ch=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">case
1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.AddBeg(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.AddEnd(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.DelBeg();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 4:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.DelEnd();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 5:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter Number To Delete = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.DelEle(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 6:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.Display();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 7:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> sl.Search(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 8:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> default : continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> } <o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal" style="margin-left: 36.0pt;">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/s531okhujp6n1t6/singly%20LL.docx?m">https://www.dropbox.com/s/s531okhujp6n1t6/singly%20LL.docx?m</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-8322290010934136432013-05-22T21:59:00.002+05:302013-05-22T21:59:45.291+05:3040. DOUBLY LINKED LIST IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class Node<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int info;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node next,prev;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node left,right;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class DoubleLL<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node start=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node end=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node curr=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int num;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DoubleLL()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void AddBeg(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.prev=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start.prev=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void AddEnd(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Node t=new Node();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.prev=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end.next=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> t.prev=end;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=t;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DelBeg()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Linked
List Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(start==end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=start.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start.prev=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DelEnd()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(num==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Linked
List Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(start==end)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> start=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> num=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end=end.prev;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> end.next=null;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Search(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Loop:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
for(curr=start;curr!=null;curr=curr.next)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(curr.info==val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("Element Found");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break Loop;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Element Not
Found");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=start;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("Start ->
");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(curr!=null)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(curr.info + "
-> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> curr=curr.next;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("End");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String[] args)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ch,val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DoubleLL dl=new DoubleLL();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("-----------------------------------");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter your
Choice");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("1 : Add
Beg 2 : Add End 3 : Del Beg 4 : Del End
5 : Display 6 : Search 7 : Exit");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ch=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter a Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.AddBeg(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("Enter a Number = ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.AddEnd(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.DelBeg();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 4:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.DelEnd();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 5:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.Display();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 6:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter Element to
Search");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> dl.Search(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 7:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> default : continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}</span></div>
<div class="MsoNoSpacing">
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; line-height: 115%;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: 10pt; line-height: 115%;">Need the code??</span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-IN; mso-bidi-font-family: "Times New Roman"; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">Download Link = <a href="https://www.dropbox.com/s/3xusdrardemdgli/doubly%20LL.docx">https://www.dropbox.com/s/3xusdrardemdgli/doubly%20LL.docx</a></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-8900289916967285492013-05-22T21:57:00.003+05:302013-05-22T21:57:58.210+05:3039. CIRCULAR QUEUE IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class CircularQueue<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int front,rear,size=5;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int a[]=new int[size];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> CircularQueue()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> front=rear=size-1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Insert(int n)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Ins:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(rear==size-1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> rear=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else rear++;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(rear==front)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("Overflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break Ins;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[rear]=n;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Remove()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(front==size-1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> front=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else ++front;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(front==rear)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Queue
Empty");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("Back ->
");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int n=front+1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(n==size)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> n=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(n<=rear)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(a[n++] + "
-> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(n==size)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> n=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Front");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String[] args)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> CircularQueue a=new CircularQueue();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in=new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int val,ch;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while (true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter your
Choice");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("\n-------------------------------------");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("1 : Add\t2
: Del\t3 : Display\t4 : Exit");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ch=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(ch)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("Enter Value To Insert");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a.Insert(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a.Remove();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a.Display();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case 4: System.exit(0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> default: continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/syug89mwzif6eyi/circular%20queue.docx">https://www.dropbox.com/s/syug89mwzif6eyi/circular%20queue.docx</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-66472089019582307512013-05-22T21:56:00.001+05:302013-05-22T21:56:08.521+05:3038. BINARY TREE IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
NodeBT<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int info;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> boolean used;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class BinaryTreeArray<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> NodeBT node[]=new NodeBT[20];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void MakeTree(int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[0]=new NodeBT();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[0].info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[0].used=true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int i=1;i<20;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[i]=new NodeBT();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[i].info=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[i].used=false;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void setLeft(int p,int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int l=2*p+1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(l>=20)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Array
Overflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else if(node[l].used==true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nInvalid
insertion");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[l].info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[l].used=true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void setRight(int p,int val)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int r=2*p+2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(r>=20)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Array
overflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else if(node[r].used==true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nInvalid
insertion");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[r].info=val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> node[r].used=true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String[] args)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BinaryTreeArray BTA=new
BinaryTreeArray();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int i=0,p,q,val;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Insertion:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(true)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Enter
numbers");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> val=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(i++==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BTA.MakeTree(val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> continue;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(val==0) break Insertion;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> p=q=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(q < 20 &&
BTA.node[q].used==true && val!=BTA.node[p].info)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> p=q;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(val<BTA.node[p].info)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q=2*p+1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q=2*p+2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(val==BTA.node[p].info)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("Duplicate Value");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else if (val<BTA.node[p].info)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BTA.setLeft(p,val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BTA.setRight(p,val);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(i=0;i<20;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(BTA.node[i].info +
" -> ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println(" End");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/uu0hdk9x6yqs6ti/binary%20tree%20in%20java.docx?m">https://www.dropbox.com/s/uu0hdk9x6yqs6ti/binary%20tree%20in%20java.docx?m</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-13967682508110526132013-05-22T21:53:00.001+05:302013-05-22T21:53:21.578+05:3037. DEPTH FIRST SEARCH IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
Stack<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int stk[]=new int[10];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int top;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Stack()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> top=-1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Push (int item)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if (top==9)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Stack
overflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> stk[++top]=item;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> boolean isEmpty()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if (top<0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return false;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int Pop()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if (isEmpty())<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Stack
underflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return 0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return (stk[top--]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void stackTop()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(isEmpty())<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Stack
underflow ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Stack top
is "+(stk[top]));<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Display()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.println("Stack-->");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int i=0;i<=top;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println(stk[i]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
Graph<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int MAXSIZE=51;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int adj[][]=new int[MAXSIZE][MAXSIZE];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int visited[]=new int [MAXSIZE];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Stack s=new Stack();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void createGraph()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
n,i,j,parent,adj_parent,initial_node;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ans=0,ans1=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter total
number elements in a Undirected Graph :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> n=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[i][j]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (int c=1;c<=50;c++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[c]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nEnter graph
structure for BFS ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> do<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter
parent node :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parent=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> do<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter
adjacent node for node "+parent+ " : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj_parent=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[parent][adj_parent]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[adj_parent][parent]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("\nContinue to add adjacent node for
"+parent+"(1/0)?");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ans1= getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> } while (ans1==1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nContinue to
add graph node?");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ans= getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }while (ans ==1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nAdjacency
matrix for your graph is :\n");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+adj[i][j]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\n");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nYour
Undirected Graph is :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nVertex
"+i+"is connected to : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if (adj[i][j]==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+j);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nEnter the
initial node for BFS traversal:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> initial_node=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> DFS (initial_node, n);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void DFS (int initial_node,int n)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int u,i;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.top = -1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.Push(initial_node);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nDFS
traversal for given graph is : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(!s.isEmpty())<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> u=s.Pop();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(visited[u]==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\n"+u);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[u]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if((adj[u][i]==1) &&
(visited[i]==0))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> s.Push(u);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[i]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> u = i;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int getNumber()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ne=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ne=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return ne;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
DFS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String args[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Graph g=new Graph();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.createGraph();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/rnx8eou3rvfhnwf/dfs.docx">https://www.dropbox.com/s/rnx8eou3rvfhnwf/dfs.docx</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-11800179242929957202013-05-22T21:51:00.000+05:302013-05-22T21:54:08.047+05:3036. BREADTH FIRST SEARCH IN JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.io.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">import
java.util.Scanner;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
Queue<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int items[]=new int[10];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int front,rear;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Queue()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> front=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> rear=-1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void Insert(int e)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(rear==9)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Queue
overflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> items[++rear]=e;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int Empty()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return(rear<front? 1:0);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int Remove()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int x=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(Empty()==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("Queue
Underflow");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return 0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x=items[front++];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return x;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">class
Graph<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int MAXSIZE=10;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int adj[][]=new int[MAXSIZE][MAXSIZE];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int visited[]=new int [MAXSIZE];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Queue q=new Queue();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void createGraph()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
n,i,j,parent,adj_parent,initial_node;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
ans=0,ans1=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter total
number elements in a Undirected Graph :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> n=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for( j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[i][j]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (int c=1;c<=50;c++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[c]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nEnter graph
structure for BFS ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> do<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter
parent node :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> parent=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> do<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nEnter
adjacent node for node "+parent+ " : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj_parent=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[parent][adj_parent]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> adj[adj_parent][parent]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">
System.out.print("\nContinue to add adjacent node for
"+parent+"(1/0)?");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ans1= getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> } while (ans1==1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nContinue
to add graph node?");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ans= getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }while (ans ==1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nAdjacency
matrix for your graph is :\n");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+adj[i][j]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\n");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nYour
Undirected Graph is :");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("\nVertex
"+i+"is connected to : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (j=1;j<=n;j++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if (adj[i][j]==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+j);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nEnter the
initial node for BFS traversal:");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> initial_node=getNumber();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> BFS (initial_node, n);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> void BFS (int initial_node,int n)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int u,i;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> u = initial_node;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[initial_node]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.println("\nBFS
traversal for given graph is : ");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print(initial_node);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q.Insert(initial_node);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> while(q.Empty()==0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> u = q.Remove();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for (i=1;i<=n;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if((adj[u][i]==1) &&
(visited[i]==0))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> q.Insert(i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> visited[i]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> System.out.print("
"+i);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int getNumber()<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int ne=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Scanner in = new Scanner(System.in);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> ne=in.nextInt();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return ne;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public
class BFS<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public static void main(String args[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> Graph g=new Graph();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.createGraph();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span><br />
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link = <a href="https://www.dropbox.com/s/719720g45rn2o6o/bfs.docx">https://www.dropbox.com/s/719720g45rn2o6o/bfs.docx</a><o:p></o:p></span></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-17421492113353602802013-05-19T18:18:00.002+05:302013-05-19T18:18:53.518+05:3035. LIANG BARSKY LINE CLIPPING ALGORITHM<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#include<iostream.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#
include<conio.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">#
include<graphics.h><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">void
main() {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
gd=DETECT,gm;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">initgraph(&gd,&gm,"C:\\TC\\BGI");<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
x1,y1,x2,y2,xmax,xmin,ymax,ymin,xx1,yy1,xx2,yy2,dx,dy,i;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">int
p[4],q[4];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">float
t1,t2,t[4];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
the lower co-ordinates of window";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>xmin>>ymin;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
the upper co-ordinates of window";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>xmax>>ymax;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">setcolor(RED);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">rectangle(xmin,ymin,xmax,ymax);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
x1:";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>x1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
y1:";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>y1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
x2:";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>x2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"Enter
y2:";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cin>>y2;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">line(x1,y1,x2,y2);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">dx=x2-x1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">dy=y2-y1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p[0]=-dx;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p[1]=dx;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p[2]=-dy;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">p[3]=dy;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">q[0]=x1-xmin;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">q[1]=xmax-x1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">q[2]=y1-ymin;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">q[3]=ymax-y1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">for(i=0;i<4;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{
if(p[i]!=0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{t[i]=(float)q[i]/p[i];}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(p[i]==0
&& q[i]<0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"line
completely outside the window";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if(p[i]==0
&& q[i]>=0)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"line
completely inside the window";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if
(t[0]>t[2])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{t1=t[0];}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{t1=t[2];}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if
(t[1]<t[3])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{t2=t[1];}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{t2=t[3];}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">if
(t1<t2)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{xx1=x1+t1*dx;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">xx2=x1+t2*dx;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">yy1=y1+t1*dy;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">yy2=y1+t2*dy;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">cout<<"line
after clipping:";<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">setcolor(WHITE);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">line(xx1,yy1,xx2,yy2);}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{cout<<"line
lies out of the window";}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">getch();<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT:</span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNDRaMhIRNxzAxTSrJ6xTyeQjwQGZCEDwmrmsCXQzSYEF88fk_7bfXET-DtydoZfZ9KmkqZECgAraS6381C-KaUqJGazpi3j0b_-KvsGsZfv5LyV7Flev2s6WbepTX5ZDa_0Zpd6h5nYsR/s1600/Prims.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="356" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNDRaMhIRNxzAxTSrJ6xTyeQjwQGZCEDwmrmsCXQzSYEF88fk_7bfXET-DtydoZfZ9KmkqZECgAraS6381C-KaUqJGazpi3j0b_-KvsGsZfv5LyV7Flev2s6WbepTX5ZDa_0Zpd6h5nYsR/s640/Prims.png" width="640" /></a></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
</div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%;">Download Link= <a href="https://www.dropbox.com/s/jhbmpn6dfzypnl4/Liang%20barsky.docx">https://www.dropbox.com/s/jhbmpn6dfzypnl4/Liang%20barsky.docx</a><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-32542326192354715942013-05-19T18:07:00.000+05:302013-05-19T18:07:19.300+05:3034. COHEN SUTHERLAND LINE CLIPPING ALGORITHM<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">Code:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">importjava.applet.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">importjava.awt.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">importjava.util.*;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">public class <a href="" name="_GoBack">CohenSutherland</a>
extends Applet<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">{<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> intxmax=90,ymax=80,xmin=40,ymin=40;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> publicint[]
set(intx,int y)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
a[]=new int[4];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(x<xmin)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[3]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[3]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(x>xmax)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[2]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[2]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(y<ymin)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[0]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[0]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(y>ymax)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[1]=1;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[1]=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
a;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> boolean
check(int a[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=0;i<a.length;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(a[i]==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
false;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int[]
produceXY(inti,int x1,int y1,float m)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
a[]=new int [2];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> float
x=0,y=0;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> switch(i)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
0:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x=xmin;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y=y1+m*(x-x1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">case 1:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x=xmax; <o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y=y1+m*(x-x1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
3:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y=ymin;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x=x1+(y-y1)/m;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> case
2:<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y=ymax;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x=x1+(y-y1)/m;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[0]=(int)x;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[1]=(int)y;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
a;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> booleandoAnd(int
a[],int b[])<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=0;i<a.length;i++)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
k=a[i]&b[i];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(k==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
false;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> return
true;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> public
void paint(Graphics g)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawRect(xmin,ymin,xmax-xmin,ymax-ymin);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawRect(xmin+100,ymin,xmax-xmin,ymax-ymin);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
a[][]=new int[2][4];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
b[][]=new int[2][4];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
c[]=new int[2];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
c1=20;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> int
x1=45,y1=45,x2=20,y2=90;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> float
m=(y2-y1)*1.0f/(x2-x1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawString(m+"
",100,100);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawLine(x1,y1,x2,y2);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[0]=set(x1,y1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> a[1]=set(x2,y2);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawString(Arrays.toString(a[0]),300,300);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawString(Arrays.toString(a[1]),400,400);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(check(a[0])&&check(a[1]))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawLine(x1,y1,x2,y2);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> else<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(doAnd())<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=a[0].length-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(a[0][i]==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> c=produceXY(a[0].length-1-i,x1,y1,m);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> b[0]=set(c[0],c[1]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawString("first
"+Arrays.toString(b[0]),200,300+c1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(check(b[0]))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x1=c[0];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y1=c[1];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> c1+=20;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> for(int
i=a[0].length-1;i>=0;i--)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(a[1][i]==1)<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> c=produceXY(a[0].length-1-i,x1,y1,m);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> b[1]=set(c[0],c[1]);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawString("second
"+Arrays.toString(b[1]),200,300+c1);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> if(check(b[1]))<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> x2=c[0];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> y2=c[1];<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> break;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> //c1+=20;<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> g.drawLine(x1+100,y1,x2+100,y2);<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">}<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-size: 10pt;">/*<applet
code="CohenSutherland.class" width=500 height=500><o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-size: 10pt;"></applet>*/<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-size: 10pt;"><br /></span></div>
<br />
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;">OUTPUT</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5phxejKblWY4_CZMd5ylM4u-FhXzXHb24cyWzYmJkP9levkPDVztidwu7vM1aAY9jiWPGAJG_ngAYKqH-zxUnsnLIegs8W6PjdDTO-WD_iUpRZxfenQ-5c1QgV_hiiv6nl8wd266o0_Sl/s1600/Prims.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5phxejKblWY4_CZMd5ylM4u-FhXzXHb24cyWzYmJkP9levkPDVztidwu7vM1aAY9jiWPGAJG_ngAYKqH-zxUnsnLIegs8W6PjdDTO-WD_iUpRZxfenQ-5c1QgV_hiiv6nl8wd266o0_Sl/s400/Prims.png" width="400" /></a></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"><br /></span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt;"></span></div>
<div class="MsoNormal">
<span style="font-size: 10pt; line-height: 115%;">Need the code??<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 10pt; line-height: 115%;">Download Link= <a href="https://www.dropbox.com/s/svjiydrqbvlen8b/CohenSutherland.java.docx">https://www.dropbox.com/s/svjiydrqbvlen8b/CohenSutherland.java.docx</a><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-92208207733493901812013-05-18T13:27:00.002+05:302013-05-18T13:27:22.579+05:3033. BEZIER CURVE<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">Code:<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.awt.*;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.applet.*;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.awt.geom.GeneralPath;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.awt.image.BufferedImage;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">public class
KBezier extends Applet<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">{<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Point[] controlPoints,curvePoints;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void init()<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> controlPoints=new
Point[4];<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> curvePoints=new
Point[25];<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> controlPoints[0]=new
Point(20,260);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> controlPoints[1]=new
Point(50,10);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> controlPoints[2]=new
Point(250,50);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> controlPoints[3]=new
Point(450,290);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for(int
i=0;i<curvePoints.length;i++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> curvePoints[i]=new
Point(0,0);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void SubDivide(Point p1,Point
p2,double t)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> if(p1.x>p2.x)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> p1.x-=Math.abs(p1.x-p2.x)*t;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> else<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> p1.x+=Math.abs(p1.x-p2.x)*t;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> if (p1.y>p2.y)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> p1.y-=Math.abs(p1.y-p2.y)*t;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> else<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> p1.y+=Math.abs(p1.y-p2.y)*t;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void Compute()<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Point[] tmp=new
Point[controlPoints.length];<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for (int i=0;
i<tmp.length; i++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> tmp[i] = new
Point(0,0);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for (int i=0;
i<curvePoints.length; i++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double t =
((double) i)/(curvePoints.length-1);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for (int
j=0; j<controlPoints.length; j++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> tmp[j]=new
Point(controlPoints[j].x, controlPoints[j].y);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> int Depth =
tmp.length;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> while
(Depth>1)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for
(int j=0; j<Depth-1; j++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> SubDivide(tmp[j],
tmp[j+1], t);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Depth--;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> curvePoints[i]=new
Point(tmp[0].x, tmp[0].y);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void Draw(Graphics2D g2d)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.setColor(Color.BLACK);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for (int i=0;
i<controlPoints.length-1; i++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.drawLine((int)
controlPoints[i].x,(int) controlPoints[i].y,<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> (int)
controlPoints[i+1].x,(int) controlPoints[i+1].y);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> GeneralPath path = new
GeneralPath(); //
Bezier curve<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.setColor(Color.RED);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> path.moveTo(curvePoints[0].x,
curvePoints[0].y);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> for (int i=1;
i<curvePoints.length; i++)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> path.lineTo(curvePoints[i].x,
curvePoints[i].y);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.draw(path);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void paint(Graphics g)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> BufferedImage image =
new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Graphics2D g2d =
image.createGraphics();<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.setColor(Color.WHITE);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g2d.fillRect(0, 0,
getWidth(), getHeight());<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Compute();<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Draw(g2d);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g.drawImage(image, 0, 0,
this);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> }<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">}<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">/*<applet
code="KBezier.class" width=500 height=300></applet>*/<o:p></o:p></span></div>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">/*</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"> </span><br />
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">OUTPUT:</span><br />
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQEOvf0wBNWd1FMDa9uYn4MMhY_bZE5NUbk-JcN52VOeJtQ-dUYwmJyykhh6YTzHH8DOrLi-jQAJqJZTPeblADyqPOxg3d-xGY4a8e5m5TV5qMwf1ruv2_xC3z2X2L1EO01BQ6WNWR0Twr/s1600/Prims.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="331" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQEOvf0wBNWd1FMDa9uYn4MMhY_bZE5NUbk-JcN52VOeJtQ-dUYwmJyykhh6YTzHH8DOrLi-jQAJqJZTPeblADyqPOxg3d-xGY4a8e5m5TV5qMwf1ruv2_xC3z2X2L1EO01BQ6WNWR0Twr/s400/Prims.png" width="400" /></a></div>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<br />
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"></span><br />
<div class="MsoNoSpacing">
<span style="font-size: 10pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-size: 10pt;">Download Link= <a href="https://www.dropbox.com/s/wtwti9tjitb01bx/KBezier.docx">https://www.dropbox.com/s/wtwti9tjitb01bx/KBezier.docx</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0tag:blogger.com,1999:blog-1157318102533304118.post-53475847452739703392013-05-18T13:24:00.002+05:302013-05-18T13:24:55.010+05:3032. KOCH CURVE<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">Code:<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.awt.*;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.applet.*;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">import
java.awt.event.*;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">public class
KKoch extends Applet implements MouseListener<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">{<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> int
iteration;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> int size = 20;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void init() <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> setBackground(Color.white);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> addMouseListener(this) ;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> iteration=1;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseMoved(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseDragged(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseReleased(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseClicked(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseEntered(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mouseExited(MouseEvent
e){} <o:p></o:p></span></div>
<div class="MsoPlainText">
<br /></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> void
koch(double x1, double y1, double
x2, double y2,int iteration, Graphics g)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> if (iteration<=1)<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {g.drawLine ((int
)x1,(int )y1,(int )x2,(int )y2);}<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> else {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double x4=x1*2/3 + x2*1/3;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double y4=y1*2/3 + y2*1/3;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double x5=x1*1/3 + x2*2/3;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double y5=y1*1/3 + y2*2/3;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double x6=(int) (0.5 * (x1+x2) + Math.sqrt(3) *
(y1-y2)/6);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> double y6=(int) (0.5 * (y1+y2) + Math.sqrt(3) *
(x2-x1)/6);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(x1,y1,x4,y4,iteration-1,g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(x4,y4,x6,y6,iteration-1,g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(x6,y6,x5,y5,iteration-1,g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(x5,y5,x2,y2,iteration-1,g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void paint(Graphics g) <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> g.setColor(Color
.black);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> Dimension w = getSize();<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(size*3, w.height - size*7, w.width - size*3, w.height
- size*7, iteration, g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(w.width/2, size*2,
size*3, w.height - size*7, iteration,
g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> koch(w.width - size*3,
w.height - size*7, w.width/2, size*2, iteration, g);<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<br /></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> public void mousePressed(MouseEvent
e) <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> {<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> iteration++;<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> repaint(); <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";"> } <o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">}<o:p></o:p></span></div>
<div class="MsoPlainText">
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; mso-bidi-font-family: "Courier New";">/*<applet
code="KKoch.class" width=600 height=600></applet>*/<o:p></o:p></span></div>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">/*</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 11.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"> </span><br />
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;">OUTPUT:</span><br />
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6IA1iF_LO9QoKUSU_6FjfvfimXWLApezwAVm7f1wgCeiRaPJbAY6O1gQlhDJwmRnCJmWa1txDKp8wSdYewA-IcG9l-wbkSjhH8vmEELRHdP28P-C6-Z-8aw7tlVXvvjrbdiatZehjHiXn/s1600/Prims.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="331" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6IA1iF_LO9QoKUSU_6FjfvfimXWLApezwAVm7f1wgCeiRaPJbAY6O1gQlhDJwmRnCJmWa1txDKp8wSdYewA-IcG9l-wbkSjhH8vmEELRHdP28P-C6-Z-8aw7tlVXvvjrbdiatZehjHiXn/s400/Prims.png" width="400" /></a></div>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"><br /></span>
<span lang="EN-US" style="font-family: "Trebuchet MS","sans-serif"; font-size: 10.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-bidi-font-family: "Courier New"; mso-bidi-language: AR-SA; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin;"></span><br />
<div class="MsoNoSpacing">
<span style="font-size: 10pt;">Need
the code??<o:p></o:p></span></div>
<div class="MsoNoSpacing">
<span style="font-size: 10pt;">Download Link= <a href="https://www.dropbox.com/s/2odoahlmzz05t83/KKoch.docx">https://www.dropbox.com/s/2odoahlmzz05t83/KKoch.docx</a><o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/04526056508954139605noreply@blogger.com0