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

  • Home
  • SEARCH
  • 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 6802035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:10:26+00:00 2026-05-26T19:10:26+00:00

I have a vector A [9 3 6 9 3 6] each 2 elements

  • 0

I have a vector A [9 3 6 9 3 6] each 2 elements represent the edge of a graph, I wan to create the adjacency matrix from this vector.

First i created the unique vector A [3 6 9] to know the size of my matrix

Second I create a matrix and fill it with 0

Third I will run a loop on A to know what edges are connected, my question is how can I tell C++ that the first element in A which is three actually represent element 0 in my matrix, same for 6 that it represent 1 and 9 is represented by 3, like this when I construct my adjacency matrix i know that 0 1 2 represent actually 3 6 9, I heard about using a map but didn t know how to construct it in my program because im new to C++.

  • 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-26T19:10:27+00:00Added an answer on May 26, 2026 at 7:10 pm

    You are essentially trying to track labels for your vertices. If each vertex has a sequentially assigned number, you can scan new vertex labels and insert the corresponding sequential number in a map, like so:

    std::map<int, std::size_t> labels;  // "int" is the label type; could be anything!
    
    std::size_t store_vertex_label(int v)
    {
      std::map<int, std::size_t>::const_iterator const it = labels.find(v);
    
      if (it != labels.end()) return it->second;
    
      const std::size_t new_number = labels.size();
      labels.insert(std::make_pair(v, new_number);
      return new_number;
    }
    

    Now as you process your input, you read one label token v at a time, send it to store_vertex_label(), and you get the corresponding sequential vertex index back.

    Your adjacency matrix will be of size labels.size() squared.

    Note that your label type doesn’t have to be an integer, it could be anything (e.g. a string).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 1x400 vector, I want to draw each 80 elements in different
I have Vector of Hashtables and each hash table has two elements with keys
I have a C++ std::vector denoted as: std::vector<GameObject*> vectorToSort; Each object in vectorToSort contains
I have a vector that I want to insert into a set . This
I have a cell array where each element consists of a vector of ids.
Sitation: overview: I have something like this: std::vector<SomeType> values; std::vector<int> indexes; struct Range{ int
I have four std::vector containers that all might (or might not) contain elements. I
I have a vector with N elements, all integers 1-M. I want to convert
If I have a container ( vector , list , etc) where each element
I am trying to create a vector that contains pointers, each pointer points to

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.