hey all...I'm working on this Skyline problem, and I'm stuck. I'm not really sure how to merge the two arrays together according to the requirements. If you are not familiar with the Skyline Problem here it is in a nutshell:
There is a city with no hills and has a set of rectangular buildings. Suppose you are viewing the city from water. Leftmost position of city is used as reference point ( horiz position 0 ). This, a building can be speified by (l, h, w), where l gives the left boundary, h the height of the buildingsm and w its width.
the program will take as input a set of n buildings, in no particular order. The program now has to extract the outline formed by the buildings. This skyline will be formed by a sequence of horizontal segments starting at position 0. It will be represented by a equence of pairs (h, w) where h is the height abd w the width.
Code:
So basically if the input from a file is:
(13, 3 4), (3,6,6,), (1,2,9), (14, 2,5), (18,4,2)
the corresponding output will be:
(0,1), (2,2), (6,6), (2,1),(0,3),(3,4),(2,1),(4,2)
Unfortunately one of the requirements is that I have to use arrays, which is very annoying. It would be much simpler using linked lists.... anyways, here is the code I have so far...and the following errors arise about my recursion:
Code:
main.cpp(81) : error C2668: 'divide' : ambiguous call to overloaded function
Code:
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <string>
#include <fstream>
using namespace std;
struct Skyline
{
int x;
int y;
Skyline *n;
};
int* divide( int *B, int *O, int n);
void skyMerge(int *, int, int*, int, int*, int);
int main()
{
ifstream inFile; //text file IO
ofstream outFile;
string inFileName;
string outFileName;
int numberOfBuildings; //first number from file
//float descriptions;
char tmp[1]; //holding the characters from file
int i = 0; //counter
int j = 0; //counter
inFile.open("hey.txt");
inFile>>numberOfBuildings;
//allocating memory for the size of the input file
int *B = new int[numberOfBuildings*3];
int *O = new int[numberOfBuildings*3];
for( i = 0; i < (numberOfBuildings*7); i++ ){
inFile>>tmp[0];
if( isdigit(tmp[0]) ) {
B[j] = atoi(tmp);
j++;
}
}
divide(B, O, numberOfBuildings);
return 0;
}
int* divide(int *B, int *&O, int n)
{
if ( n == 1 )
{
return O;
}
int n1 = (n/2);
int n2 = (n - n1);
int *skyLeft = new int[n1*3];
int *skyRight = new int[n2*3];
divide(B, skyLeft, n1);
divide(B, skyRight, n2);
skyMerge(skyLeft, n1, skyRight, n2, O, n);
}
void skyMerge(int *s1, int n1, int *s2, int n2, int *&O, int n)
{
}
any ideas? suggestions?