From 51edf8de50c8049bb66ea9db212b7e6b631f0e00 Mon Sep 17 00:00:00 2001 From: Day <51234957+deyenelira@users.noreply.github.com> Date: Tue, 27 Oct 2020 16:27:30 -0300 Subject: [PATCH 1/4] Create mergesort.c --- sort/mergesort.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sort/mergesort.c diff --git a/sort/mergesort.c b/sort/mergesort.c new file mode 100644 index 000000000..131b35abb --- /dev/null +++ b/sort/mergesort.c @@ -0,0 +1,56 @@ +#include +#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 Date: Tue, 27 Oct 2020 16:30:30 -0300 Subject: [PATCH 2/4] Create quicksort.c --- sort/quicksort.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 sort/quicksort.c diff --git a/sort/quicksort.c b/sort/quicksort.c new file mode 100644 index 000000000..01c8524b3 --- /dev/null +++ b/sort/quicksort.c @@ -0,0 +1,50 @@ +#include +#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 Date: Tue, 27 Oct 2020 16:32:28 -0300 Subject: [PATCH 3/4] Create toposort.cpp --- sort/toposort.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 sort/toposort.cpp diff --git a/sort/toposort.cpp b/sort/toposort.cpp new file mode 100644 index 000000000..ba5a2662e --- /dev/null +++ b/sort/toposort.cpp @@ -0,0 +1,20 @@ +#include +#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; +} From 39dd409a11dbf71f982fa059b13caf9d40663474 Mon Sep 17 00:00:00 2001 From: Day <51234957+deyenelira@users.noreply.github.com> Date: Tue, 27 Oct 2020 16:34:33 -0300 Subject: [PATCH 4/4] Create graph.c --- Graphs/graph.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Graphs/graph.c 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