Advertisement
Ilya_konstantinov

18A

Feb 26th, 2024 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | Source Code | 0 0
  1. #include <iostream>
  2.  
  3. using std::cin;
  4. using std::cout;
  5.  
  6. struct Node {
  7.   int data;
  8.   Node *next;
  9. };
  10.  
  11. Node* create(int _data) {
  12.   Node *t = new Node();
  13.   t->data = _data;
  14.   t->next = nullptr;
  15.   return t;
  16. }
  17.  
  18. void add_back(Node *&root, Node *added) {
  19.   root->next = added;
  20. }
  21.  
  22. #include "func.h"
  23.  
  24. int main() {
  25.   int n; cin >> n;
  26.   int a; cin >> a;
  27.   Node *root = create(a), *last;
  28.   last = root;
  29.   for (int i = 0; i < n - 1; ++i) {
  30.     cin >> a;
  31.     Node *t = create(a);
  32.     add_back(last, t);
  33.     last = t;
  34.   }
  35.   print(root);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement