Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct List {
- int data;
- List* next;
- };
- int main(){
- int size;
- cin >> size;
- if(size == 0){
- cout << "lol ok";
- return 0;
- }
- int data;
- cin >> data;
- auto head = new List{data, nullptr};
- auto it = head;
- for(auto i = 1; i < size; ++i){
- cin >> data;
- it->next = new List{data, nullptr};
- it = it->next;
- }
- for(auto i = head; ; i = i->next){
- if(i->next == nullptr){
- i->next = new List{228, nullptr};
- break;
- }
- }
- for(auto i = head; i != nullptr; i = i->next){
- cout << i->data << " ";
- }
- for(auto i = head; i != nullptr;){
- auto t = i;
- i = i->next;
- delete t;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement