0

I am running this simple code to be used in segment trees. Shows a lot of errors. Could anyone explain where am I going wrong here? It basically has problems with declaring a vector of nodes.

`

// C++ program to show segment tree operations like construction, query and update
#include <bits/stdc++.h>
using namespace std;

struct node{
    int open, closed, full;
    node(int op, int cl, int f){
        open  = op;
        closed = cl;
        full = f;
    }
};

void printseg(vector<node> &v){
    for(auto it: v){ 
        cout<<it.open<<" ";
        cout<<it.closed<<" ";
        cout<<it.full;
    }
    cout<<"\n";
}

void build(int index, int low, int high, string s, vector<node> seg){
    if(low==high){
        seg[index] = node(s[low] == '(', s[low] == ')', 0);
        return;
    }
    int mid = (low+high)/2;
    build(2*index+1, low, mid, s, seg);
    build(2*index+2, mid+1, high, s, seg);
    seg[index] = merge_nodes(seg[2*index+1], seg[2*index+2]);
}

void solve4(){
    string s;
    cin>>s;
    int n = s.size();
    vector<node> seg(4*n);
    build(0, 0, n-1, s, seg);
    printseg(seg);
}

`

0 Answers0