diff --git a/.gitignore b/.gitignore index 6636748..0665f7e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ introsortquickmergelongjmp quicksortM3insertion quicksortinsertion cppsort +cppmultisetsort bubblesortsentinela combsort countingsort diff --git a/Makefile b/Makefile index 426ca1a..04cfeca 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ BINARY?=dummy\ radixsort\ redblacktreesort\ cppsort\ + cppmultisetsort\ pqsortsimple\ heapsort\ countingsort\ @@ -101,6 +102,9 @@ heapsort: main.c heapsort.c priority-queue.c cppsort: main.c cppsort.cpp g++ -D__$@__ $(CXXFLAGS) $^ -o $@ +cppmultisetsort: main.c cppmultisetsort.cpp + g++ -D__$@__ $(CXXFLAGS) $^ -o $@ + printorder: @for T in 08 09 10 11 12 13 14 15 16 17 18 19 20;do\ printf " %s " $$T;\ diff --git a/README.md b/README.md index e77d37a..f8ea76a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ nomenclatura indica exatamente do que se trata: POTENCIA-CATEGORIA - [combsort](combsort.c) - [countingsort](countingsort.c) - [cppsort](cppsort.cpp) +- [cppmultisetsort](cppmultisetsort.c) - [heapsort](heapsort.c) - [insertionsort](insertionsort.c) - [insertionsortslow](insertionsortslow.c) diff --git a/cppmultisetsort.cpp b/cppmultisetsort.cpp new file mode 100644 index 0000000..b68836b --- /dev/null +++ b/cppmultisetsort.cpp @@ -0,0 +1,22 @@ +/* + * Copyright(C) 2020, Bruno César Ribas + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ +#include "ordenacaomacros.h" +#include + +void cppmultisetsort(Item *v, int l, int r) { + std::multiset st(v + l, v + r + 1); + int i = 0; + for (auto it = st.begin(); it != st.end(); ++it) { + v[l + i++] = *it; + } +} diff --git a/cppmultisetsort.h b/cppmultisetsort.h new file mode 100644 index 0000000..8e8b787 --- /dev/null +++ b/cppmultisetsort.h @@ -0,0 +1,23 @@ + +/* + * Copyright(C) 2020, Bruno César Ribas + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ +#ifndef __cppmultisetsortH__ +#define __cppmultisetsortH__ +#include "ordenacaomacros.h" +void cppmultisetsort(Item *, int, int); + +#ifdef __cppmultisetsortonly__ +#define sort(v, l, r) cppmultisetsort(v, l, r); +#endif + +#endif diff --git a/main.h b/main.h index f5e02f8..2dcd643 100644 --- a/main.h +++ b/main.h @@ -110,6 +110,10 @@ #define __cppsortonly__ #include "cppsort.h" +#elif defined(__cppmultisetsort__) +#define __cppmultisetsortonly__ +#include "cppmultisetsort.h" + #elif defined(__bstsort__) #define __bstsortonly__ #include "bstsort.h"