实现文件.里面的细节,关系到输出的方式.可以选择多种输出方式,没有大肆包装. // block.cpp -- 模拟集成电路板实现文件 #include "stdafx.h" #include "block.h" namespace block { // private: void Test :: m_Merge (const int left, const int leftEnd, const int right, const int rightEnd) { int i, j, k ; for (i = left, j = right, k = 0; i <= leftEnd && j <= rightEnd; ++k) { if (m_list[i].item <= m_list[j].item) m_tempArray[k] = m_list[i++] ; else m_tempArray[k] = m_list[j++] ; } while (i <= leftEnd) m_tempArray[k++] = m_list[i++] ; while (j <= rightEnd) m_tempArray[k++] = m_list[j++] ; for (i = left, k = 0; i <= rightEnd; ++i, ++k) m_list[i] = m_tempArray[k] ; } void Test :: m_MergeSort (const int start, const int end) { if (start < end) { int middle = (start + end) / 2 ; m_MergeSort (start, middle) ; m_MergeSort (middle + 1, end) ; m_Merge (start, middle, middle + 1, end) ; } } // public: Test :: Test (void) { m_input = NULL ; m_list = NULL ; m_size = 0 ; m_minXMin = m_maxXMax = 0 ; m_stepLenth = 0 ; } Test :: Test (const Block * const input, const int size, const int stepLenth) { // Ignore censor error m_input = input ; m_size = size * 2 ; m_list = new Cell[m_size] ; for (int i = 0, j = 0; i < size; ++i, ++j) { m_list[j].isMin = true ; m_list[j].item = input[i].xMin ; m_list[j].number = i ; ++j ; m_list[j].isMin = false ; m_list[j].item = input[i].xMax ; m_list[j].number = i ; } m_tempArray = new Cell[m_size] ; m_MergeSort (0, m_size - 1) ; delete []m_tempArray ; m_minXMin = m_list[0].item ; m_maxXMax = m_list[m_size - 1].item ; m_stepLenth = stepLenth ; } void Test :: CalculateAndOutput (void) { IntervalTree * t = new IntervalTree ; int scanLine, start ; int number, count ; for (scanLine = m_minXMin, start = 0; scanLine < m_maxXMax; scanLine += m_stepLenth) { while (m_list[start].item <= scanLine) { number = m_list[start].number ; if (m_list[start].isMin) { // It can use t -> Search () so that it will discover the leftmost block has overlaped it. // Obviously, change following code will get many diffrent realizations. count = t -> SearchAll (m_input[number].yMin, m_input[number].yMax) ; if (count) std :: cout << "Overlap No." << number << std :: endl ; t -> Insert (m_input[number].yMin, m_input[number].yMax, number) ; } else t -> Delete (m_input[number].yMin, m_input[number].yMax) ; ++start ; } } delete t ; } Test :: ~Test (void) { delete []m_list ; } }