Академический Документы
Профессиональный Документы
Культура Документы
h>
#include <stdlib.h>
typedef struct {
nod *top;
}stack;
typedef struct {
nod *head, *tail;
}queue;
// VARIABILE GLOBALE
nod **N;
int n;
// initializare stiva
void stack_init(stack *s){
s->top=NULL;
}
}
top=s->top;
topData=top->data;
s->top=s->top->next;
free(top);
return topData;
}
stack s;
int data;
int *visited = create_visited_array(n);
nod *p;
stack_init(&s);
stack_push(&s,position);
while (!stack_empty(&s)){
data=stack_top(&s);
if (visited[data-1]==NULL){
printf("%d\n",data );
visited[data-1]=1;
p= *(N+(data-1));
while (p && visited[p->data-1]){
p=p->next;
if(p){
stack_push(&s,p->data)
}
else {
stack_pop(&s);
}
// eliberam tabloul
free (visited);
}
}
free(visited);
return 0;
}