Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <memory.h>
- #include <iterator>
- #include <cassert>
- #include <fstream>
- #include <iomanip>
- #include <cstdlib>
- #include <bitset>
- #include <vector>
- #include <cstdio>
- #include <string>
- #include <queue>
- #include <deque>
- #include <cmath>
- #include <ctime>
- #include <stack>
- #include <set>
- #include <map>
- using namespace std;
- //#define int long long
- #define fi first
- #define se second
- #define pb push_back
- #define mp make_pair
- #define all(x) x.begin() , x.end()
- typedef long long ll;
- typedef long double ld;
- typedef pair < ll , ll > pll;
- typedef pair < int , int > pii;
- template < typename T >
- T read(){
- T p = 1 , x = 0;
- char s = getchar();
- while(s == ' ' || s == '\n') s = getchar();
- if(s == '-') p = -1 , s = getchar();
- while(s >= '0' && s <= '9'){
- x = x * 10 + s - '0';
- s = getchar();
- }
- return x * p;
- }
- template < typename A , typename B >
- void Umax(A &a , const B &b){
- if(a < b)
- a = b;
- }
- template < typename A , typename B >
- void Umin(A &a , const B &b){
- if(a > b){
- a = b;
- }
- }
- ll bin_pow (ll a , ll n) {
- if(n == 0){
- return 1;
- }
- if(n % 2 == 1){
- ll cnt = a * bin_pow(a , n - 1);
- return cnt;
- }
- else {
- ll cnt = bin_pow(a , n / 2);
- return cnt * cnt;
- }
- }
- const int N = (int) 1e6 + 10;
- const int MOD = (int) 1e9 + 7;
- const int INF = (int) 1e9 + 10;
- const ll LLINF = (ll) 1e18 + 10;
- const int dx [] = { 0 , 0 , 1 , -1 };
- const int dy [] = { 1 , -1 , 0 , 0 };
- class List {
- public:
- List() {
- head = nullptr;
- tail = nullptr;
- size_of_list = 0;
- }
- ~List() {
- while(this->head) {
- Node *next = this->head->pNext;
- delete head;
- size_of_list--;
- head = next;
- }
- }
- void push_back(string data) {
- Node *new_element = new Node(data);
- if(size_of_list == 0) {
- head = new_element;
- tail = new_element;
- } else {
- tail->pNext = new_element;
- new_element->pPrev = tail;
- tail = new_element;
- }
- size_of_list++;
- }
- void push_front(string data) {
- Node *new_element = new Node(data);
- if(size_of_list == 0) {
- head = new_element;
- tail = new_element;
- } else {
- head->pPrev = new_element;
- new_element->pNext = head;
- head = new_element;
- }
- size_of_list++;
- }
- void pop_front() {
- Node *temp = this->head;
- this->head = this->head->pNext;
- this->head->pPrev = nullptr;
- delete temp;
- size_of_list--;
- }
- void pop_back() {
- Node *temp = this->tail;
- this->tail = this->tail->pPrev;
- this->tail->pNext = nullptr;
- delete temp;
- size_of_list--;
- }
- void show_list() {
- Node *curr = head;
- while(curr != nullptr) {
- cout << curr->data << endl;
- curr = curr->pNext;
- }
- }
- string get_index(int index) {
- int counter = 0;
- Node *curr = this->head;
- while(curr != nullptr){
- if(counter == index) {
- break;
- }
- curr = curr->pNext;
- counter++;
- }
- return curr->data;
- }
- private:
- class Node {
- public:
- Node *pPrev;
- Node *pNext;
- string data;
- Node(string data, Node *pPrev = nullptr, Node *pNext = nullptr) {
- this->data = data;
- this->pPrev = nullptr;
- this->pNext = nullptr;
- }
- };
- Node *head;
- Node *tail;
- int size_of_list;
- };
- int main ()
- {
- freopen("input.txt" , "r" , stdin);
- freopen("output.txt" , "w" , stdout);
- ios_base::sync_with_stdio(false);
- List t;
- t.push_back("fdjk");
- t.push_front("fjdkfffff");
- t.show_list();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement