Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include "list_node.h"
  3.  
  4. list_node *generate_list(unsigned amount)
  5. {
  6. list_node list;
  7. list_node *list_ptr = &list;
  8. list.item = amount;
  9. if (amount > 0)
  10. {
  11. list.next = generate_list(amount - 1);
  12. }
  13. return list_ptr;
  14. }
  15.  
  16. int print_list(list_node *list)
  17. {
  18. //std::cout << list->item << std::endl;
  19. //std::cout << list->next->item << std::endl; // it's not in scope?
  20. list_node tmp = *list;
  21. std::cout << tmp.item << std::endl;
  22. if (tmp.next)
  23. {
  24. print_list(tmp.next);
  25. }
  26. return 0;
  27. }
  28.  
  29. int main()
  30. {
  31. list_node *k = generate_list(6);
  32. std::cout << k->next->next->next->next->next->next->item << std::endl; // this works, yields 0
  33. //print_list(&k); // doesn't work, gives a location
  34. }
Add Comment
Please, Sign In to add comment