fork download
  1. Non- Destructive:
  2. ilist double_copy(ilist x) {
  3. if (x==NULL) return NULL;
  4. ilist head = malloc(sizeof(struct ilist_node));
  5. head ->first = x->first * 2;
  6. head ->rest = NULL;
  7. ilist prev = head;
  8. for (ilist a = x->rest; a != NULL; a = a->rest) {
  9. ilist tmp = malloc(sizeof(struct ilist_node));
  10. tmp->first = a->first * 2;
  11. tmp->rest = NULL;
  12. prev ->rest = tmp;
  13. prev = tmp;
  14. }
  15. return head;
  16. }
  17.  
  18.  
  19.  
  20. Destructive:
  21. ilist double_destructive(ilist x) {
  22. for (ilist a = x; a != NULL; a = a->rest) {
  23. a->first = a->first * 2;
  24. }
  25. return x;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: expected constructor, destructor, or type conversion before ‘-’ token
stdout
Standard output is empty