fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct Node {
  4. int data; // Корисні дані (наш вантаж)
  5. Node* next; // Вказівник на наступний вузол
  6.  
  7. // Конструктор для зручного створення
  8. Node(int val) {
  9. data = val;
  10. next = nullptr;
  11. }
  12. };
  13.  
  14. int main() {
  15. int* x1;
  16. x1=new int[5];
  17. Node* head;
  18. head=nullptr;
  19. Node* newNode;
  20. newNode=new Node(5);
  21.  
  22. newNode->next=head;
  23. head=newNode;
  24. // newNode->data=5;
  25. // cout<<head->data;
  26. newNode=new Node(99);
  27. newNode->next=head;
  28. head=newNode;
  29. // cout<<newNode->
  30. newNode=new Node(10);
  31. newNode->next=head;
  32. head=newNode;
  33. cout<<head->data;
  34. cout<<head->next->data;
  35. cout<<head->next->next->data<<endl;
  36. newNode=head;
  37.  
  38. while(newNode!=nullptr){
  39. cout<<newNode->data<<" ";
  40. newNode=newNode->next;
  41. ;
  42. }
  43. // your code goes here
  44.  
  45. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
10995
10 99 5