Created
June 20, 2018 02:18
-
-
Save Salivala/0331331d0f79539c69aca3ca7b94348f 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