fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct Node{
  4. int data;
  5. Node* next;
  6. };
  7. void append(Node** head,int data)
  8. {
  9. Node* new_node = new Node();
  10. new_node->data = data;
  11. new_node->next = *head;
  12. *head = new_node;
  13.  
  14. }
  15. int main() {
  16. Node* head=NULL;
  17. append (&head,100);
  18. append(&head,200);
  19. while (head != NULL)
  20. {
  21. cout<<" "<<head->data;
  22. head = head->next;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5360KB
stdin
Standard input is empty
stdout
 200 100