Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // kolokwium.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <cstdlib>
- using namespace std;
- class Element
- {
- public:
- Element *next;
- int value;
- Element ( int val): value(val) {}
- int getValue()
- {
- return value;
- }
- Element getNext()
- {
- return *next;
- }
- };
- class List
- {
- private:
- Element *First;
- int counter = 0;
- public:
- List()
- {
- First = nullptr;
- }
- void display()
- {
- Element *temp = First;
- while (temp)
- {
- cout << temp->getValue() << " ";
- temp = temp->next;
- }
- }
- void add(int value)
- {
- Element *nowy = new Element(value);
- if (First == nullptr)
- {
- First = nowy;
- }
- else
- {
- Element *temp = First;
- while (temp->next)
- {
- temp = temp->next;
- }
- temp->next = nowy;
- nowy->next = nullptr;
- }
- counter++;
- }
- void erase(int value)
- {
- Element *temp = First;
- if (First->getValue() == value)
- {
- First = temp->next;
- }
- for (int i = 1; i < counter; i++)
- {
- if (temp->getValue() == value)
- {
- temp = temp->next;
- }
- temp->next = temp->next->next;
- }
- }
- };
- int main()
- {
- List my_list;
- int M, N;
- int temp;
- cin >> M;
- for (int i = 0; i < M; i++)
- {
- cin >> temp;
- my_list.add(temp);
- }
- cin >> N;
- for (int i = 0; i < N; i++)
- {
- cin >> temp;
- my_list.erase(temp);
- }
- my_list.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement