线性表

var a = [1,3,5,6], b = [2,4,6,7,8],i=j=0,c=[];
while(i < a.length && j < b.length){
     if(a[i]>=b[j]){
        c.push(b[j]);
        j++; 
     }else{
        c.push(a[i]);
        i++;
     }
}
while(i < a.length){
    c.push(a[i]);
    i++;
}
while(j < b.length){
    c.push(b[j]);
    j++;
}
console.dir(c);

合并倒叙线性表 

Array.prototype.exists = function(n){
   for(var i in this)
     if(this[i] == n) return true;
   return false;
}
var a = [23,4,5,2], b = [7,34,3,23] ,c = [];
for(var i in b){
  if(!a.exists(b[i])) a.push(b[i]); 
}
console.dir(a);
合并线性表

 

posted @ 2013-03-13 09:18  ﹏Sakura  阅读(147)  评论(0编辑  收藏  举报