All pastes #2120588 Raw Edit

Anonymous

public text v1 · immutable
#2120588 ·published 2012-02-22 01:37 UTC
rendered paste body
// modifies il1 and il2 to form an ilist consisting of the
// elements from il1 followed by the elements from il2
// references to il1 and il2 cease to be valid ilists
ilist iappend_destroy(ilist il1, ilist il2){
   // special cases
   if (iempty_huh(il1) && iempty_huh(il2)) return iempty();
   if (il1 == NULL) return il2;
   if (il2 == NULL) return il1;
   // if they point to the same struct, make a new struct
   if (il1 == il2) il2 = icopy(il2);
   
   // remember length of il1, il2
   int il1_length = ilength(il1);
   int il2_length = ilength(il2);
   
   // creating temp il1
   ilist temp = il1;

   // finding last element in il1
   while(temp->rest != NULL) {
      temp = temp->rest; 
   }
   
   // linking final node to il2
   temp->rest = il2;
   il1->length = il1_length + il2_length;
   return il1;
}