Created
June 20, 2018 02:48
-
-
Save Salivala/0492f9b7e188ae55f81d02e35e2661a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "list_node.h" | |
list_node *generate_list(unsigned amount) | |
{ | |
list_node list; | |
list_node *list_ptr = &list; | |
list.item = amount; | |
if (amount > 0) | |
{ | |
list.next = generate_list(amount - 1); | |
} | |
return list_ptr; | |
} | |
int print_list(list_node *list) | |
{ | |
//std::cout << list->item << std::endl; | |
//std::cout << list->next->item << std::endl; // it's not in scope? | |
list_node tmp = *list; | |
std::cout << tmp.item << std::endl; | |
if (tmp.next) | |
{ | |
print_list(tmp.next); | |
} | |
return 0; | |
} | |
int main() | |
{ | |
list_node *k = generate_list(6); | |
std::cout << k->next->next->next->next->next->next->item << std::endl; // this works, yields 0 | |
//print_list(&k); // doesn't work, gives a location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment