Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Linked Lists - Sorted Merge

function Node(data) {
  this.data = data === undefined ? null : data;
  this.next = null;
}

function sortedMerge(first, second) {
  
 let a = new Node()
 const dummy = a
  
  
  while(first  && second ){
    if( first.data <second.data){
      a.next = first
      first = first.next
    }
    else{
      a.next= second
      second= second.next
    }
    a= a.next
    }
    
 
    if(first){
      a.next=first
    }
    if(second){
      a.next = second
    }
 
  
     return dummy.next
  
  
}
 
PREVIOUS NEXT
Tagged: #Linked #Lists #Sorted #Merge
ADD COMMENT
Topic
Name
4+4 =