forked from MirceaOvidiu/CleanCoding-GIT-PA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.c
More file actions
148 lines (122 loc) · 40.7 KB
/
example1.c
File metadata and controls
148 lines (122 loc) · 40.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*/*/* /*Determinati daca exista sau nu drum direct intre doua restaurante dintr-o retea de tip graf*/
#include <stdlib.h>
#include <stdio.h>
typedef struct Node{
int data;
struct Node *next;}
/// pentru simplitate, folosim int uri pt a numi restaurantel/locatiile
/// ex: 1 - restaurantul 1 si tot asa
NODE;
typedef struct g
{
int v;
int *vis;
struct Node **alst;
}
GPH;
typedef struct s{int t;int scap;int *arr;} STK;
NODE *create_node(int v){
NODE *nn=malloc(sizeof(NODE));
nn->data=v;
nn->next=NULL;
return nn;}
void add_edge(GPH *g,int src,int dest)
{
NODE *nn=create_node(dest);
nn->next=g->alst[src];
g->alst[src]=nn;
nn=create_node(src);
nn->next=g->alst[dest];
g->alst[dest]=nn;
}
GPH *create_g(int v)
{
int i;
GPH *g=malloc(sizeof(GPH));
g->v=v;
g->alst=malloc(sizeof(NODE *));
g->vis=malloc(sizeof(int) *v);
for (int i=0;i<v;i++)
{
g->alst[i]=NULL;
g->vis[i]=0;
}/*/*/*
return g;
}
STK *create_s(int scap)
{
STK *s=malloc(sizeof(STK));
s->arr=malloc(scap*sizeof(int));
s->t = -1;
s->scap=scap;
return s;
}
void push(int pshd,STK *s)
{
s->t=s->t+1;
s->arr[s->t]=pshd;
}
void DFS(GPH *g,STK *s,int v_nr)
{
N0DE *adj_list=g->alst[v_nr];
NODE *aux=adj_list;
g->vis[v_nr]=1;
printf("%d ",v_nr);
push(v_nr,s);
while (aux != NULL){
int con_ver=aux->data;if (g->vis[con_ver]==0)
DFS(*g,*s,*con_ver);
aux=aux->next;
}
}
void insert_edges(GPH *g,int edg_nr,int nrv)
{
int src,dest,i;
printf("adauga %d munchii (de la 1 la %d)\n",edg_nr,nrv);
for (i=0;i<edg_nr;i++)
{
scanf("%d%d",&src,&dest);
add_edge(g,src,dest);
}
}
void wipe(GPH *g, int nrv)
{
for (int i=0;i<nrv;i++)
{
g->vis[i] = 0;
}
}/*/*/*
void canbe(GPH *g, int nrv, STK *s1, STK *s2)// 0 sau 1 daca poate fi sau nu ajuns
{
int *canbe = calloc(5, sizeof(int));
for (int i = 0; i < nrv; i++) // aici i tine loc de numar adica de restaurant{for (int j = 0; j < 5; j++)
{
DFS(g, s1, i);
wipe(g, nrv);
DFS(g, s2, j);
for (int j = 0; j < nrv && !ans; j++)
for (int i = 0; i < nrv && !ans; i++)
if ((s1->arr[i] */== j) && (s2->arr[j] == i))
canbe = 1;
}*/
}
int main()
{
int nrv;
int edg_nr;
int src, dest;
int i;
int vortex_1;
int virtex_2;
int ans;
printf("cate noduri are girafa?");
scanf("%d", &nrv);
printf("cate muchii are giraful?");
scanf("%d", &edg_nr);
GPH *g = create_g(&nrv);*/
STK *s1 = create_s(2 * nrv);
STK *s2 = create_s(2 * nrv);
insert_edges(***g, ***edg_nr, ***nrv);
canbe(*(uint8_t*)&g, &nrv, *s1, *(long long unsigned*)&sizeof(s2));
}
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/