Advertisement
Ne-Biolog

Untitled

Mar 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. //#define int long long
  24.  
  25. #define fi first
  26. #define se second
  27. #define pb push_back
  28. #define mp make_pair
  29. #define all(x) x.begin() , x.end()
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33. typedef pair < ll , ll > pll;
  34. typedef pair < int , int > pii;
  35.  
  36. template < typename T >
  37. T read(){
  38. T p = 1 , x = 0;
  39. char s = getchar();
  40. while(s == ' ' || s == '\n') s = getchar();
  41. if(s == '-') p = -1 , s = getchar();
  42. while(s >= '0' && s <= '9'){
  43. x = x * 10 + s - '0';
  44. s = getchar();
  45. }
  46. return x * p;
  47. }
  48.  
  49. template < typename A , typename B >
  50. void Umax(A &a , const B &b){
  51. if(a < b)
  52. a = b;
  53. }
  54.  
  55. template < typename A , typename B >
  56. void Umin(A &a , const B &b){
  57. if(a > b){
  58. a = b;
  59. }
  60. }
  61.  
  62. ll bin_pow (ll a , ll n) {
  63. if(n == 0){
  64. return 1;
  65. }
  66. if(n % 2 == 1){
  67. ll cnt = a * bin_pow(a , n - 1);
  68. return cnt;
  69. }
  70. else {
  71. ll cnt = bin_pow(a , n / 2);
  72. return cnt * cnt;
  73. }
  74. }
  75.  
  76. const int N = (int) 1e6 + 10;
  77. const int MOD = (int) 1e9 + 7;
  78. const int INF = (int) 1e9 + 10;
  79. const ll LLINF = (ll) 1e18 + 10;
  80. const int dx [] = { 0 , 0 , 1 , -1 };
  81. const int dy [] = { 1 , -1 , 0 , 0 };
  82.  
  83.  
  84. class List {
  85. public:
  86. List() {
  87. head = nullptr;
  88. tail = nullptr;
  89. size_of_list = 0;
  90. }
  91.  
  92. ~List() {
  93. while(this->head) {
  94. Node *next = this->head->pNext;
  95. delete head;
  96. size_of_list--;
  97. head = next;
  98. }
  99. }
  100.  
  101. void push_back(string data) {
  102. Node *new_element = new Node(data);
  103. if(size_of_list == 0) {
  104. head = new_element;
  105. tail = new_element;
  106. } else {
  107. tail->pNext = new_element;
  108. new_element->pPrev = tail;
  109. tail = new_element;
  110. }
  111. size_of_list++;
  112. }
  113.  
  114. void push_front(string data) {
  115. Node *new_element = new Node(data);
  116. if(size_of_list == 0) {
  117. head = new_element;
  118. tail = new_element;
  119. } else {
  120. head->pPrev = new_element;
  121. new_element->pNext = head;
  122. head = new_element;
  123. }
  124. size_of_list++;
  125. }
  126.  
  127. void pop_front() {
  128. Node *temp = this->head;
  129. this->head = this->head->pNext;
  130. this->head->pPrev = nullptr;
  131. delete temp;
  132. size_of_list--;
  133. }
  134.  
  135. void pop_back() {
  136. Node *temp = this->tail;
  137. this->tail = this->tail->pPrev;
  138. this->tail->pNext = nullptr;
  139. delete temp;
  140. size_of_list--;
  141. }
  142.  
  143. void show_list() {
  144. Node *curr = head;
  145. while(curr != nullptr) {
  146. cout << curr->data << endl;
  147. curr = curr->pNext;
  148. }
  149. }
  150.  
  151. string get_index(int index) {
  152. int counter = 0;
  153. Node *curr = this->head;
  154.  
  155. while(curr != nullptr){
  156. if(counter == index) {
  157. break;
  158. }
  159. curr = curr->pNext;
  160. counter++;
  161. }
  162. return curr->data;
  163. }
  164. private:
  165. class Node {
  166. public:
  167. Node *pPrev;
  168. Node *pNext;
  169. string data;
  170.  
  171. Node(string data, Node *pPrev = nullptr, Node *pNext = nullptr) {
  172. this->data = data;
  173. this->pPrev = nullptr;
  174. this->pNext = nullptr;
  175. }
  176. };
  177.  
  178. Node *head;
  179. Node *tail;
  180. int size_of_list;
  181. };
  182.  
  183.  
  184.  
  185. int main ()
  186. {
  187. freopen("input.txt" , "r" , stdin);
  188. freopen("output.txt" , "w" , stdout);
  189. ios_base::sync_with_stdio(false);
  190.  
  191. List t;
  192. t.push_back("fdjk");
  193. t.push_front("fjdkfffff");
  194. t.show_list();
  195.  
  196.  
  197.  
  198.  
  199. return 0;
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement