LATEST NEWS
NOTICE BOARD...!!!
Latest topics
ActionScript program for Binary Search
Page 1 of 1
ActionScript program for Binary Search
Record 2:
2. Creating Loops
Binary Search
---------------------------------------------------------------
var a:Array=[20,10,5,55,6];
var n=a.length;
for(var i=0;i<n;i++)
{
for(var j=0;j<i;j++)
{
if(a[i]<a[j])
{
var tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
}
}
trace("after sorting:");
for(var i=0;i<n;i++)
{
trace(a[i]);
}
var l=0;
var n=a.length,h=n,m=int((l+h)/2),f=0,key=55;
while(l<=m)
{
if(key==a[m])
{
var f=1;
break;
}
else if(key>a[m])
{
l=m+1;
m=int((l+h)/2);
}
else
{
h=m-1;
m=int((l+h)/2);
}
}
trace("given key="+key);
if(f==1)
trace("element found");
else
trace("element not found");
-------------------------------------------------------------------------
2. Creating Loops
Binary Search
---------------------------------------------------------------
var a:Array=[20,10,5,55,6];
var n=a.length;
for(var i=0;i<n;i++)
{
for(var j=0;j<i;j++)
{
if(a[i]<a[j])
{
var tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}
}
}
trace("after sorting:");
for(var i=0;i<n;i++)
{
trace(a[i]);
}
var l=0;
var n=a.length,h=n,m=int((l+h)/2),f=0,key=55;
while(l<=m)
{
if(key==a[m])
{
var f=1;
break;
}
else if(key>a[m])
{
l=m+1;
m=int((l+h)/2);
}
else
{
h=m-1;
m=int((l+h)/2);
}
}
trace("given key="+key);
if(f==1)
trace("element found");
else
trace("element not found");
-------------------------------------------------------------------------
Output
after sorting:
5
6
10
20
55
given key=55
element found
Similar topics
» ActionScript program for Drawing a Circle
» ActionScript program for Scripting Mask
» ActionScript program for Drawing a Rectangle
» ActionScript program for Checking the System language
» ActionScript program for Sorting and Reversing of an Array
» ActionScript program for Scripting Mask
» ActionScript program for Drawing a Rectangle
» ActionScript program for Checking the System language
» ActionScript program for Sorting and Reversing of an Array
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Mon Sep 14, 2009 12:07 pm by NIETGALAXY
» Bollywood actresses In Sarees
Mon Sep 14, 2009 12:05 pm by NIETGALAXY
» Childhood photos of Bollywood stars
Mon Sep 14, 2009 12:02 pm by NIETGALAXY
» How to Use the Secret
Sat Sep 05, 2009 1:35 pm by NIETGALAXY
» How to Be A Teacher's Pet
Sat Sep 05, 2009 1:28 pm by NIETGALAXY
» How to Get into the Habit of Studying for a Test
Sat Sep 05, 2009 1:24 pm by NIETGALAXY
» Vodafone Free GPRS hack
Tue Aug 18, 2009 8:31 pm by anil kumar
» How To Get Big Arms?
Tue Aug 18, 2009 8:24 pm by anil kumar
» Airtel GPRS hack
Tue Aug 18, 2009 8:20 pm by anil kumar