Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ilist iappend_destroy(ilist il1, ilist il2){
- if(!il1) return il2; // so the following "while" is correct
- int lengthToAdd = ilength(il2); // <- new
- ilist temp = il1;
- while(temp->rest) {
- temp->length+=lengthToAdd; // <- new
- 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;
- }
Add Comment
Please, Sign In to add comment