Deque-STL

  • + 1 comment

    Got error: solution.cc: In function ‘void printKMax(int*, int, int)’: solution.cc:15:13: error: ‘mydp’ was not declared in this scope mydp.push_front(arr[i]); ^ solution.cc:25:13: error: ‘mydp’ was not declared in this scope mydp.pop_front();

    void printKMax(int arr[], int n, int k){ //Write your code here.

    deque<int> mydq;
    int max = arr[0];
    mydq.push_back(arr[0]);
    for(int i = 1; i < k; ++i){
        if(arr[i] >= max){
            mydq.push_back(arr[i]);
            max = arr[i];
        }else{
            mydp.push_front(arr[i]);
        }
    }
    cout << max << " ";
    
    for(int i = k -1; i < n; ++i){
        if(arr[i] > max){
            max = arr[i];
            mydq.push_back(arr[i]);
        }else{
            mydp.pop_front();
            mydq.push_front(arr[i]);
        }
        cout << max << " ";
    }
    

    }

    why??