Dealing with quenches through dynamic lists



  • I'm studying C++ and I'm gonna have to do the job by presenting turns and glasses as dynamic lists. Objective: There are two sets of whole numbers between 0 and 1,000. From the elements of the first line, There's no one in the second to focus on the turn.

    I understand how to initiate the glass and turn and the necessary function for work, but how to perform a function that compares the glasses and lays their elements in line, I have no idea. I don't know if there's a point in writing the code on the question, because it's just not ready, but it's still here. Maybe it'll help.

    #include <iostream>
    #include <ctime>
    

    using namespace std;

    struct Stack {
    int data;
    Stack* next;
    };

    void InitStack(Stack*& top) {
    top = NULL;
    }

    void push(Stack*& top, int value) {
    Stack* tmp = new Stack;
    tmp->next = top;
    top = tmp;
    top->data = value;
    }

    int pop(Stack*& top) {
    Stack* tmp = top;
    int d = top->data;
    top = top->next;
    delete(tmp);
    return d;
    }

    bool Empty(Stack*& top) {
    return (top == NULL);
    }

    void nullStack(Stack*& top) {
    Stack* tmp;
    while (!Empty(top)) {
    tmp = top;
    top = top->next;
    delete(tmp);
    }
    }
    void print(Stack*& top) {
    if (!Empty(top)) {
    Stack* tmp = top;
    while (!Empty(tmp)) {
    cout << tmp->data << " ";
    tmp = tmp->next;
    }
    cout << endl;
    delete(tmp);
    }
    else {
    cout << "Стек пуст!\n";
    }
    }
    class Queue {
    private:
    struct Node
    {
    int data;
    Node* next;
    };
    Node* head, * tail;

    public:
    Queue() {
    head = NULL;
    tail = NULL;
    }

    bool empty() {
        return head == NULL;
    }
    
    void add(int value) {
        if (empty()) {
            head = new Node;
            head-&gt;data = value;
            head-&gt;next = NULL;
            tail = head;
        }
        else {
            tail-&gt;next = new Node;
            tail = tail-&gt;next;
            tail-&gt;data = value;
            tail-&gt;next = NULL;
        }
    }
    
    int del() {
        if (empty()) {
            cout &lt;&lt; "Очередь пуста!\n";
            return 0;
        }
        else {
            int d = head-&gt;data;
            Node* tmp = head;
            head = head-&gt;next;
            delete tmp;
            return d;
        }
    }
    
    void nullQueue() {
        Node* tmp;
        while (!empty()) {
            tmp = head;
            head = head-&gt;next;
            delete tmp;
        }
    }
    
    void print() {
        Node* temp = head;     
        while (temp != NULL)
        {
            cout &lt;&lt; temp-&gt;data &lt;&lt; " "; 
            temp = temp-&gt;next;
        }
        cout &lt;&lt; endl;
    }
    

    };
    int main() {
    return 0;
    }



  • Let you have A and B stacks.

    Now you retrieve one element from A, then compare all elements B with it, throwing them into C. If you haven't found analogue, you're putting an element in line A.

    Next step, you take a new element from A, and compare it to elements from C, moving them to B.

    And so on until A's over.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2