Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ilist iappend(ilist il1, ilist il2){
- if(!il1) return il2; // so the following "while" is correct
- ilist temp = il1;
- while(temp->rest) temp = temp->rest;
- // now temp points to the last entry of il1
- while(il2) {
- temp->rest = il2;
- temp = temp->rest;
- il2 = il2->rest;
- }
- // now every node of il2 is appended to il1 and we just need to append the finishing null
- temp->rest = 0;
- return il1;
- }
- int main(void){
- ilist c = icons_destroy(4, icons_destroy(3, iempty()));
- ilist b = icons_destroy(1, icons_destroy(2, iempty()));
- ilist d = iappend_destroy (c, b);
- iprint("il", d);
- printf("%d", ilength(d)); // prints 4 3 1 2 in this case
- idelete(d);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement