fork download
  1. #include <iostream>
  2. #include <new>
  3. using namespace std;
  4.  
  5. struct List{
  6. int Data;
  7. List *Next;
  8. };
  9. void ShowList(List *node){
  10. cout << "List = ";
  11. while(node){
  12. cout << node->Data << ", ";
  13. node = node->Next;
  14. }
  15. }
  16. inline List* NewList(int data){
  17. return new List{data, NULL};
  18. }
  19. void AppenList(List* node, int data) {
  20. while(node->Next) {
  21. node = node->Next;
  22. } node->Next = NewList(data);
  23. }
  24. int main() {
  25. List *head = NewList(-1);
  26. AppenList(head, 3);
  27. AppenList(head, 2);
  28. AppenList(head, 1);
  29.  
  30. ShowList(head);
  31. return 0;
  32. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
List = -1, 3, 2, 1,