Blogroll

This blog is created for education about engineering students.All the engineering students are get free downloadable books here. not only books and also different software also available here

Sorting an array elements

Procedure:
step 1: Open flash 8
step 2: Select flash document
step 3: select 1st layer, 1st frame on that document and write source code on Actions Frame
step 4: To check output press ctrl+enter(test movie)


SourceCode:
var a:Array=[20,10,5,55,6];
var n=a.length;
for(var i=0;i
{
 for(var j=0;j
 {
  if(a[i]
  {
    var tmp=a[i];
    a[i]=a[j];
    a[j]=tmp;
   }
  }
}

trace("after sorting:");
for(var i=0;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");

No comments:

Post a Comment

Total Pageviews