please convert to C language

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

please convert to C language

 

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ll t;

    cout << "Enter number of test cases: ";
    cin >> t;

    while (t--) {
        ll n, m;

        cout << "Enter number of nodes and edges: ";
        cin >> n >> m;

        // declare a vector of stacks of size (n+1)
        // since index start from 0.
        stack<int> v1[n + 1];
        // declare a vector of queue of size (n+1)
        // since index start from 0.
        queue<int> v2[n + 1];

        cout << "Enter tree 1: ";
        for (ll i = 0; i < m; i++) {
            ll x, y; //enter the elements of its.
            cin >> x >> y;
            v1[x].push(y);
        }

        cout << "Enter tree 2: ";
        for (ll i = 0; i < m; i++) {
            ll x, y;
            cin >> x >> y; //enter elements of tree 2.
            v2[x].push(y);
        }
        bool flag;
        // iterate through each node.
        for (int i = 1; i <= n; i++) {
            // store nodes of tree 1 connected components in stack
            stack<int>& s = v1[i];
            // store nodes of tree 1 connected components in queue
            queue<int>& q = v2[i];

            // declare a boolean variable to check mirror
            // property among the elements.
            flag = true;
            //compare the stack top to queue top.
            while (!s.empty() and !q.empty()) {
                // if not similar then break from the loop.
                if (s.top() != q.front()) {
                    flag = false;
                    break;
                }
                s.pop();
                q.pop();
            }
            // if not similar then break from the nodes loop
            // since no further comparison is needed.
            if (flag == false)
                break;
        }

        // check if mirror or not.
        cout << "Is Mirror: ";
        if (flag == true)
            cout << "YES"
                 << "\n";
        else
            cout << "NO"
                 << "\n";
    }

    return 0;
}

 

Output:

Enter number of test cases: 3
Enter number of nodes and edges: 4 4
Enter tree 1: 1 2 1 3 2 4 2 5
Enter tree 2: 1 2 1 3 2 5 2 4
Is Mirror: NO
Enter number of nodes and edges: 3 2
Enter tree 1: 1 2 1 3
Enter tree 2: 1 3 1 2
Is Mirror: YES
Enter number of nodes and edges: 3 3
Enter tree 1: 1 2 1 3 2 4
Enter tree 2: 1 3 1 2 2 4
Is Mirror: YES
Transcribed Image Text:Enter number of test cases: 3 Enter number of nodes and edges: 4 4 Enter tree 1: 1 2 1 3 2 4 2 5 Enter tree 2: 1 2 1 3 2 5 2 4 Is Mirror: NO Enter number of nodes and edges: 3 2 Enter tree 1: 1 2 1 3 Enter tree 2: 1 3 1 2 Is Mirror: YES Enter number of nodes and edges: 3 3 Enter tree 1: 1 2 1 3 2 4 Enter tree 2: 1 3 1 2 2 4 Is Mirror: YES
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY