diff --git a/Graphs/graph.c b/Graphs/graph.c new file mode 100644 index 000000000..d8ba2a5d9 --- /dev/null +++ b/Graphs/graph.c @@ -0,0 +1,86 @@ +#include +#include +typedef struct { + int **matrix; + int numEdge; + int *Mark; +}G; +G create_graph(int n) { + G grafoAux; + grafoAux.Mark = (int*) malloc(n*sizeof(int)); + grafoAux.matrix = (int**) malloc(n*sizeof(int*)); + for(int i=0; i +#include +#include +void merge(int a[], int inicio, int meio, int fim){ +int *temp, p1, p2, tamanho, i, j, k; +int fim1 = 0, fim2 =0; +tamanho = fim-inicio+1; +p1 = inicio; +p2 = meio+1; +temp = (int*) malloc(tamanho*sizeof(int)); + if(temp!=NULL){ + for(i=0; imeio) fim1=1; + if(p2>fim) fim2=1; + }else{ + if(!fim1){ + temp[i]=a[p1++]; + }else{ + temp[i]=a[p2++]; + } + } + } + for(j=0, k=inicio; j +#include +#include +int partition(long long int v[], int l, int r){ + long long int p = v[l]; + int i = l; + int j = r+1; + long long int swap; + +do{ + do{ + i++; + }while(!(v[i]>=p||i>=r)); + do{ + j--; + }while(v[j]>p); + swap = v[i]; + v[i] = v[j]; + v[j] = swap; +}while(i +#include +using namespace std; +#define n 7 +void toposort(vector> grafo, int *visitados, stack &pilha, int no){ + visitados[no] = 1; + for(auto w: grafo[no]){ + if(visitados[w]==0){ + toposort(grafo, visitados, pilha, w); + } + pilha.push(no); + } +} +int main() +{ + vector> grafo(n); + stack pilha; + int visitados[n]={}; + return 0; +}