Jump to content

Vectors

- - - - -

  • Please log in to reply
1 reply to this topic

#1
vasil_9x

vasil_9x

    Newbie

  • Members
  • PipPip
  • 13 posts
Could you explain me how does this code works. I mean what does a[u].push_back(v);
a[v].push_back(u); mean?
vector a[1024];

void input()

{

int m,n;

cin>>n>>m;

for(int i=1;i<=m;i++)

{

int u,v;

cin>>u>>v;

a[u].push_back(v);

a[v].push_back(u);

}

}

Edited by ZekeDragon, 07 March 2011 - 09:41 AM.
Please use [CODE] tags (the # button) when posting code.


#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
You have an array of vectors, which is similar to this:

int* array[1024];


push_back() is a method which creates a new element and appends it to it's vector. If you would go through all vector elements and use push_back() on all of them, then you'd have something like this:

int array[1024][1];


A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users