Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node {
- int value = 0;
- Node *next = NULL;
- Node *prev = NULL;
- Node(int value) {
- this->value = value;
- }
- };
- class List {
- public:
- void pushTail(int valToAdd) {
- Node * newNode = new Node(valToAdd);
- if (head == NULL) {
- head = newNode;
- tail = newNode;
- return;
- }
- tail->next = newNode;
- tail = newNode;
- };
- void popTail()
- {
- Node * temp = tail;
- tail = tail -> prev;
- tail -> next = NULL;
- delete temp;
- return;
- };
- void popHead()
- {
- Node *temp = head;
- head = head->next;
- return;
- };
- void pushHead(int valToAdd) {
- Node * newNode = new Node(valToAdd);
- if (head == NULL) {
- head = newNode;
- tail = newNode;
- return;
- }
- newNode->next = head;
- head = newNode;
- };
- void printAll() {
- Node * buff = head;
- cout<<"print List:" << endl;
- while (buff != NULL) {
- cout<< buff->value << endl;
- buff = buff->next;
- }
- }
- private:
- Node * head = NULL;
- Node * tail = NULL;
- };
- int main() {
- List list;
- list.pushHead(1);
- list.pushHead(4);
- list.pushTail(8);
- list.printAll();
- list.popTail();
- list.printAll();
- }
- /*Node *temp = tail;
- tail = NULL;
- tail -> next = tail;
- return;*/ //как вырезать весь список сконца LUL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement