Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Node
- {
- string str;
- Node *next;
- Node *prev;
- int priority;
- };
- class List
- {
- Node *head;
- Node *tail;
- Node *temp;
- public:
- void show();
- void add(int x, string str);
- void delet();
- Node *found(int priority);
- List();
- ~List();
- };
- #include "List.h"
- void List::show()
- {
- Node *temp = head;
- while (temp!=NULL)
- {
- cout << temp->str<<endl;
- temp = temp->next;
- }
- }
- void List::add(int x, string str)
- {
- Node *arr = new Node;
- if (head != NULL && tail != NULL)
- {
- temp=head;
- arr = found(x);//ищем начало части с нужным приоритетом
- }
- temp = NULL;
- temp->priority = x; //тут вылетает исключение
- temp->str = str;
- if (head == NULL && tail == NULL)
- {
- head = temp;
- tail = temp;
- }
- else if(head->next==NULL)
- {
- head->next = temp;
- tail = temp;
- }
- else if (arr->next == NULL)
- {
- arr->next = temp;
- tail = temp;
- }
- else
- {
- Node *tmp = new Node;
- tmp = arr->next;
- arr->next = temp;
- temp->prev = arr;
- temp->next = tmp;
- tmp->prev = temp;
- }
- }
- Node * List::found(int priority)
- {
- if (temp->priority == priority)
- return temp;
- else
- return temp = temp->next;
- }
- List::List()
- {
- head = NULL;
- tail = NULL;
- temp = NULL;
- }
- List::~List()
- {
- }
Add Comment
Please, Sign In to add comment