Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <stdlib.h>
- #include <cmath>
- #include <queue>
- using namespace std;
- class Queue {
- private:
- struct Node {
- int value;
- Node* next;
- Node* prev;
- };
- Node *first;
- Node *last;
- int *p_darr;
- int n;
- int dlina;
- public:
- Queue() {
- first = NULL;
- last = first;
- }
- void add () {
- Node *temp;
- int v = rand() % 15;
- if(first == NULL) {
- first = new Node;
- first->value = v;
- first->next = NULL;
- last = first;
- first->prev = NULL;
- }
- else {
- temp = new Node;
- temp->value = v;
- temp->next = NULL;
- last->next = temp;
- temp->prev = last;
- last = temp;
- }
- }
- void fill() {
- srand(time(0));
- cout<<"Vvedite dliny ocheredi ";
- cin>>dlina;
- for(int i=0;i<dlina;i++) {
- add();
- }
- }
- void get() {
- for(int i= 0;i<dlina;i++){
- cout<<first->value<<" ";
- first = first->next;
- }
- }
- void get2() {
- for(int i= 0;i<(dlina+n);i++){
- cout<<first->value<<" ";
- first = first->next;
- }
- }
- void back() {
- Node *temp;
- for (int i = 0; i < (dlina - 1); i ++) {
- temp = last->prev;
- last = temp;
- }
- first = last;
- while(temp->next != NULL) {
- temp = last->next;
- last = temp;
- }
- }
- void move() {
- cout<<"Vvedite kol-vo elementov dla peremech iz 1 ocheredi vo 2: ";
- cin>>n;
- p_darr = new int[n];
- Node *temp;
- cout<<"move elements: ";
- for(int i = 0; i<n ; i++) {
- p_darr[i] = first->value;
- cout<<p_darr[i]<<" ";
- temp=first;
- first=first->next;
- delete temp;
- }
- }
- void metamorf() {
- Node *temp;
- for (int i = 0; i<n; i ++) {
- temp = new Node;
- temp->next = NULL;
- temp->value = p_darr[i];
- last->next = temp;
- temp->prev = last;
- last = temp;
- }
- }
- ~Queue() {
- delete [] p_darr;
- }
- };
- int main()
- {
- Queue a;
- Queue b;
- a.fill();
- cout<<"1 ochered: ";
- a.get();
- cout<<endl;
- a.back();
- cout<<endl<<endl;
- b.fill();
- cout<<"2 ochered: ";
- b.get();
- b.back();
- cout<<endl<<endl;
- a.move();
- cout<<endl<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement