fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct List
  5. {
  6. int Data;
  7. List *Next;
  8. };
  9.  
  10. void ShowList(List *current)
  11. {
  12. while(current!=NULL)
  13. {
  14. cout<<current->Data<<" ";
  15. if(current->Next)
  16. cout<<current->Next->Data<<endl;
  17. else
  18. cout<<"NULL"<<endl;
  19.  
  20. current=current->Next;
  21. }
  22. }
  23.  
  24. bool NewList(List *head)
  25. {
  26. if(head==NULL)
  27. {
  28. List *NewNode = new List();
  29.  
  30. NewNode->Data = 100;
  31. NewNode->Next = NULL;
  32.  
  33. head = NewNode;
  34.  
  35. ShowList(head);
  36. return false;
  37. }
  38. }
  39.  
  40. int main() {
  41. List *OneNode=NULL;
  42. NewList(OneNode);
  43.  
  44. cout<<"after: "<<endl;
  45. ShowList(OneNode);
  46.  
  47. cout<<endl<<"end."<<endl;
  48. return 0;
  49. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
100  NULL
after: 

end.