I'm trying to go through a list of structs which consist of a string and an int. The strings are just lines that consist urls, and there are duplicates of some of the urls. They are in alphabetical order so any and all duplicates are right next to each other. The int is a counter used to count how many copies of a certain url there is. What I need to do is print out only a single instance of each url, along with a count of how many instances of that url were originally in the array. The thing I'm trying to figure out is how to remove all but one instance of each url I was wondering if someone might know a technique to do this.
Here is the code I have up to this point for this particular part of the program:
void histogram(const int MaxPages, istream& input, ostream& output)
{
string temp;
int current = 0;
CountedLocation *dynamicArray = new CountedLocation[MaxPages];
int toBeMoved = current - 1;
getline(input, temp);
while(!input.eof())
{
temp = extractTheRequest(temp);
toBeMoved = current-1;
dynamicArray[current].locator = temp;
if(isAGet(temp))
{
temp = extractLocator(temp);
while (toBeMoved >= 0 && temp < dynamicArray[toBeMoved].locator)
{
dynamicArray[toBeMoved+1].locator = dynamicArray[toBeMoved].locator;
dynamicArray[toBeMoved+1].counter = 1;
--toBeMoved;
}
dynamicArray[toBeMoved+1].locator = temp;
dynamicArray[toBeMoved+1].counter = 1;
}
current++;
getline(input, temp);
}
for(int i=0; i < MaxPages; i++)
{
string temp = dynamicArray[i].locator;
temp = "\"" + temp + "\"";
dynamicArray[i].locator = temp;
}
//int tempMax = MaxPages;
for(int i=0; i < current; i++)
{
if(search(dynamicArray, MaxPages, dynamicArray[i].locator) == search(dynamicArray, MaxPages, dynamicArray[i+1].locator))
{
int toBeMoved = i;
dynamicArray[i+1].counter = dynamicArray[i].counter + 1;
while (toBeMoved < current-1)
{
dynamicArray[toBeMoved] = dynamicArray[toBeMoved+1];
++toBeMoved;
}
--current;
if(search(dynamicArray, MaxPages, dynamicArray[i].locator) == search(dynamicArray, MaxPages, dynamicArray[i+1].locator))
continue;
}
}
for(int i=0; i < current+1; i++)
{
cerr << dynamicArray[i].locator<< ", " << dynamicArray[i].counter << endl;
output << dynamicArray[i].locator<< ", " << dynamicArray[i].counter << endl;
}
delete [] dynamicArray;
}