Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bfs( Graf G, int nodSursa )
- {
- int* vizitate; /* pentru marcarea nodurilor vizitate */
- vizitate = calloc(G.n, sizeof(int));
- if (vizitate == NULL) printErr();
- coada Q; /* coada nodurilor - intregi */
- int i, v, w; /* noduri */
- initializeza( &Q );
- for ( i = 0; i < G.n; i++ ) /* marcam toate nodurile ca nevizitate */
- vizitate[ i ] = NEVIZITAT;
- vizitate[ nodSursa ] = VIZITAT; /* marcam nodul sursa ca vizitat */
- //(procesam informatia pt nodSursa;
- printf("%d",nodSursa);
- enqueue(&Q,nodSursa );
- // nodSursa va fi primul nod scos din coada
- while( ! goala( &Q ))
- {
- v = dequeue( &Q );
- while(G.t[v]!=NULL)
- {
- w=G.t[v]->v;
- if ( vizitate[ w ] == NEVIZITAT )
- {
- vizitate[ w ] = VIZITAT;
- printf("%d",w);
- enqueue(&Q,w);
- }
- G.t[v]=G.t[v]->next;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement