fork download
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. struct num
  6. {
  7. int l=0;
  8. num* p_next=nullptr;
  9. };
  10.  
  11. void add (int size, num*& head)
  12. {
  13. for (int i = 0; i<size; i++)
  14. {
  15. num* newnode = new num;
  16. newnode->l = rand()%100;
  17. newnode->p_next = head;
  18. head = newnode;
  19. }
  20. }
  21.  
  22. int extract (num*& head)
  23. {
  24. int n;
  25. n = head->l;
  26. num* tmp = head;
  27. head = head->p_next;
  28. delete tmp;
  29. return n;
  30. }
  31.  
  32. void print (num*& head)
  33. {
  34. while (head != nullptr)
  35. cout << extract(head) << endl;
  36. }
  37.  
  38. int main ()
  39. {
  40. srand (time(0));
  41. num* head = nullptr;
  42. add (10, head);
  43. print (head);
  44. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
75
48
65
8
31
93
6
54
99
94