의가 나는 Rectangle
클래스과 같이 있다고 가정 해 봅시다 :다형성
class Rectangle {
public:
double width;
double height;
}
지금 내가 처음 힙 width
을 기반으로해야한다는 점을 제외 힙로 Rectangles
두 가지 가능성이 다른 목록을 저장하고자 두 번째는 height
입니다. 또한 stl의 make_heap
함수를 사용하여 heapify하는 기능을 사용하고자합니다. 이상적으로는 힙에 .heapify()
을 호출 할 수 있어야하며, 속한 클래스를 기반으로 올바른 펑션을 make_heap
으로 전달하여 동적 덤프를 사용하여 힙을 무겁게 처리해야합니다.
class Heap {
public:
vector<Rectangle> data;
virtual bool comp(Rectangle a, Rectangle b);
void heapify() { make_heap(data.begin(), data.end(), comp); }
// other methods that make use of comp directly
}
class WidthHeap : public Heap {
bool comp(Rectangle a, Rectangle b); // compares by width
}
class HeightHeap : public Heap {
bool comp(Rectangle a, Rectangle b); // compares by height
}
이 모든 잘못 난 그냥 내가 당신의 도움이 필요 왜 C++에서의 기능을 이해하지 못하는 것 같아요 때문에 : 내가 가지고있는 것은 다음과 같다.
구체적으로 "모두 잘못"이라고 생각하십니까? –