jeudi 26 mars 2015

Length of a linked list in C++


I have a struct A like the following:



struct A
{
int v;
double weight;
A* next;
A(int x, double w, A* t){
v=x;
next = t;
weight = w;
}

};


I am also saving these linked lists in a vector in the following manner:



typedef A* link;
vector<link>adj;


Now, I would like to find the length of the linked list for adj[i]. I know that it is like traversing the linked list and incrementing a count to get the length of the linked list. For some reason I am not getting what I want. I was wondering, if someone could give me some pointers. Thanks




Aucun commentaire:

Enregistrer un commentaire