Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 884055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:41:42+00:00 2026-05-15T12:41:42+00:00

I’m near the end of a program I had got to code for my

  • 0

I’m near the end of a program I had got to code for my university courses, but I got into a last trouble: formatting the output!

It’s nothing about code: this is just cosmetics (but I need to fix that cause my output’s got to respect some standards).

Basically, my program will read a .csv file and process that by dividing the resulting graph into clusters. I want to have them numbered, no matter how (I don’t care if it starts with 2 instead of 1 as long as the numbers are correct ofc). Problem is I can’t figure out how to do that O-o

I’ve already got a proper data structure to handle my clustering activity: every node of the graph points to some list. If I have n clusters, I’ll have n lists. The lists are instanced inside the Vertex class and the algorithm will merge them during runtime, so I can’t number them as simply as I would, were they in a vector or something.

So now I have, say, n lists. I can start easily by looking at the 1st vertex (they’re in the vector V) and following the pointer.
After doing that, I’m in the first list. I can move on it and get every node it points to that list, and I’d want my program to put a “1” on that inside the map.
Then I’d look inside V for another vertex whose list is different from before, and again get to the list and save the nodes with “2” and so on.

My counter doesn’t work properly: asking for 3 clusters on a .csv file, the output was like this:

c 1 1
c 2 1
c 3 1
c 4 1
c 5 1
c 6 5
c 7 1
c 8 1
c 9 1
c 10 1
c 11 1
c 12 5
c 13 5
c 14 1
c 15 1
c 16 1
c 17 1
c 18 17
c 19 17
c 20 17
c 21 17
c 22 5
c 23 17
c 24 17
c 25 17
c 26 17
c 27 17
c 28 17
c 29 17
c 30 17
c 31 5
c 32 5

Clusters labels are 1, 5, 17 instead of 1, 2, 3 lol U_U

map<int, int> clusterProcessor(Grafo &G, map_t &Map, int clusters, vector<Vertex*> &V {
    map<int, int> clustermap;
    list<Vertex*>::iterator listiter;
    int j;
    int counter = 1;
    for (j=1; j < V.size(); ++j) {
        if (V[j]->getMyset()->front() != V[j-1]->getMyset()->front())
            counter++;
        for (listiter = V[j]->getMyset()->begin(); listiter != V[j]->getMyset()->end();
                listiter++)
            clustermap.insert(pair<int, int> ( (*listiter)->id, counter) );
    }
    return clustermap;
}

void clusterPrinter(map<int, int> m) {
    map<int, int>::iterator i;
    for (i = m.begin(); i != m.end(); i++)
        cout << "c " << i->first << " " << i->second << endl;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:41:43+00:00Added an answer on May 15, 2026 at 12:41 pm

    Notice that the number is always the row number of the row right before it appears. This suggests that counter++ is always executing.

    And sure enough, it is.

    Perhaps you meant to compare the values of the first elements of each cluster, instead of the iterator addresses?

    Based on the subsequent mapping you establish, I’d suggest changing

    if (V[j]->getMyset()->front() != V[j-1]->getMyset()->front() ) counter++;
    

    to

    if (V[j]->getMyset()->begin()->id != V[j-1]->getMyset()->begin()->id) counter++;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.