Advertisement
smatskevich

Lesson11

Feb 4th, 2023
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main1() {
  5.   std::vector<int> v(5);
  6.   for (int& x : v) std::cin >> x;
  7.   v.insert(v.begin() + 2, 7);
  8.   v.erase(v.begin() + 1);
  9.  
  10.   for (int x : v) std::cout << x << " ";
  11.   std::cout << std::endl;
  12.   return 0;
  13. }
  14.  
  15. struct Node {
  16.   int Data = 0;
  17.   Node* Next = nullptr;
  18.  
  19.   explicit Node(int a) : Data(a) {}
  20. };
  21.  
  22. int main() {
  23.   Node* head = nullptr;
  24.   int x = 0;
  25.   Node* current = head;
  26.   while (std::cin >> x && x != 0) {
  27.     if (head == nullptr) {
  28.       head = current = new Node(x);
  29.     } else {
  30.       current->Next = new Node(x);
  31.       current = current->Next;
  32.     }
  33.   }
  34.  
  35.   for (Node* current = head; current != nullptr; current = current->Next) {
  36.     std::cout << current->Data << " ";
  37.   }
  38.  
  39.   return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement