c# - Find the bars indexes in the largest Rectangular Area in a Histogram -
i have histogram , need find indices of bars inside largest rectangle under histogram. way find largest rectangle under histogram explained in link
http://www.geeksforgeeks.org/largest-rectangle-under-histogram/
and in many other links on web. i'm not able retrieve indexes of bars inside output rectangle. ideas? thank you
from link have posted:
for hist[tp], ‘left index’ previous (previous tp) item in stack , ‘right index’ ‘i’ (current index).
so have edit getmaxarea() method store left , right indexes of max area:
int getmaxarea(int hist[], int n) { // .. int rindex=0; int lindex=0; while (i < n) { //.. if (max_area < area_with_top) {max_area = area_with_top; lindex=i-(max_area/hist[tp])+1; rindex=i; } //.. } while (s.empty() == false) { //.. if (max_area < area_with_top) {max_area = area_with_top; lindex=i-(max_area/hist[tp])+1; rindex=i; } //.. } //.. cout << "indexs: " << lindex << " " << rindex << "\n"; // u may pass them main method, if needed return max_area; }
im not c++ programmer, may optimize try, can find edited code here: ideone: online compiler
Comments
Post a Comment