hello
i have an adjancy matrix for example
[0] 0,44, ( 0 : node / 0,44 it neighbors)
[1] 1,3,12,
[2] 2,33,40,

i need to remove all of the neighbors from a list and push them in another one
i wanna start from adj[specific number].begin to adj[specific number].end to remove the neighbors from the first list and push them in another one as i said
i tried this but it did not work

  for(list<int>::iterator it = adj[argmax].begin(); it != adj[argmax].end(); it++)
        {
            if(color.at(*it) == 'w')
            {
                wlist.remove(*it);
                color.at(*it) = 'g';
                glist.push_back(*it);
            }
        }

help me please :)

This is not adequate. Please provide all of your relevant code, variable definitions, etc.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv) {
//reading file
    ifstream inFile;
    inFile.open("Problem.dat_50_50_0",std::ifstream::in);

    if ( !inFile ) {
        cout << "file could not be opened !" << endl;
        exit(-1);
    }

    string line;
    int n, value;
    vector<int> weight;

    inFile >> n;
// filling the weight vector
    for ( int i = 0; i < n; ++i)
        if ( inFile >> value )
            weight.push_back(value);

    vector<vector<int> > matrix(n , vector<int>(n));
    vector<vector<int> > adj(n);
    vector<int> degree;
    vector<char> color (n , 'w');
    list<int> wlist;
    list<int> glist;
    list<int> blist;

    /*cout << "color elements test: \n";
    for (int i = 0; i < n; ++i) {
        cout << color.at(i) << ", ";
    }*/

    cout << "the weights are: \n";
    for (int i = 0; i < n; ++i) {
        cout << weight.at(i) << ", ";
    }

    cout << endl;
// get the adjancey matrix "the matrix of neighboors"
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            inFile >> value;
            matrix.at(i).at(j) = value;
            if (i == j)
                matrix[i][j] = 0;
            if (value == 1)
                adj.at(i).push_back(j);
        }
        degree.push_back(adj[i].size());    
    }


    cout << "the neighbor of each elemnt are: \n";
    for (int i = 0; i < adj.size(); ++i) {
        cout << "[" << i << "]: ";
        for (int j = 0; j < adj.at(i).size(); ++j) {
            cout << adj.at(i).at(j) << ",";
        }
        cout << endl;
    }
    cout << "the degree are: \n";
    for (int i = 0; i < n; ++i) {
        cout << degree.at(i) << ", ";
    }
// filling the wlist
   for( int i=0; i < n; i++ ) {
       wlist.push_back(i);
   }
        list<int>::iterator theIterator;
// desplaying white list "it's just a test"
        cout << "white list elements are: \n" ;
   for( theIterator = wlist.begin(); theIterator != wlist.end(); theIterator++ ) {
     cout << *theIterator << " ";
   }

    int cd;
    int W =0;
    int argmax = -1;
    double bval = -1.0;
    double nval;
    vector< vector<int> >::iterator row;
    vector<int>::iterator col;
    //while (!wlist.empty()){
// loop to get the Weight of the white neighbors
    for(list<int>::iterator it = wlist.begin(); it != wlist.end(); it++)
    {

    for (row = adj.begin(); row != adj.end(); row++) {
    for (col = row->begin(); col != row->end(); col++) {
        if(color.at(*col) == 'w')
        {   
            W = W +weight.at(*col);
        }
    }
   }
        nval = (double) W / (double) weight[*it];
        cout << "nval =" << nval << "\n" ;
        if (argmax == -1)
        {
            bval = nval;
            argmax = *it;
        }
        else
            if(nval > bval)
            {
                bval = nval;
                argmax = *it;
            }
    }
     degree[argmax] = 0;
    cout << "the selected node with argmax of degree/weight is = " << argmax; 

//add neighbors to glist
    for (row = adj.begin(); row != adj.end(); row++) {
    for (col = row->begin(); col != row->end(); col++) {
        if(color.at(*col) == 'w')
        {   wlist.remove(*col);
            color.at(*col) = 'g';
            glist.push_back(*col);
        }
    }
   }
//delete gray vertices that hv no white neighbors  
    for(list<int>::iterator it = glist.begin(); it != glist.end(); it++)
    {
        if (degree.at(*it) == 0)
        {
            it = glist.erase(it);
        }
    }
// add best_vertex to blist
    if (color.at(argmax) == 'w')
        wlist.remove(argmax);
    else
        glist.remove(argmax);
    blist.push_back(argmax);
    color.at(argmax) = 'b';



   cin.ignore();
    return 0;
}

i'm having problem in the (// loop to get the Weight of the white neighbors) part when i compile an error of list iterator not incompatible pop up

for(list<int>::iterator it = wlist.begin(); it != wlist.end(); it++)
    {
    for (row = adj.begin(); row != adj.end(); row++) {
    for (col = row->begin(); col != row->end(); col++) {
        if(color.at(*col) == 'w')
        {   
            W = W +weight.at(*col);
            break;

        }
    }
   }

Better. I'll look at it when I have a minute. This will help others to analyze and comment as well.

Which of these 3 lines is generating the compiler error?

    for(list<int>::iterator it = wlist.begin(); it != wlist.end(); it++)
    {
        for (row = adj.begin(); row != adj.end(); row++) {
            for (col = row->begin(); col != row->end(); col++) {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.