Advertisement
nato_fernandes

Untitled

Feb 15th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ilist iappend(ilist il1, ilist il2){
  2.     if(!il1) return il2; // so the following "while" is correct
  3.     ilist temp = il1;
  4.     while(temp->rest) temp = temp->rest;
  5.     // now temp points to the last entry of il1
  6.     while(il2) {
  7.         temp->rest = il2;
  8.         temp = temp->rest;
  9.         il2 = il2->rest;
  10.     }
  11.     // now every node of il2 is appended to il1 and we just need to append the finishing null
  12.     temp->rest = 0;
  13.     return il1;
  14. }
  15. int main(void){
  16.     ilist c = icons_destroy(4, icons_destroy(3, iempty()));
  17.     ilist b = icons_destroy(1, icons_destroy(2, iempty()));
  18.     ilist d = iappend_destroy (c, b);
  19.     iprint("il", d);
  20.     printf("%d", ilength(d)); // prints  4 3 1 2 in this case
  21.     idelete(d);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement