Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adição de ordenação utilizando o multiset do c++ #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ introsortquickmergelongjmp
quicksortM3insertion
quicksortinsertion
cppsort
cppmultisetsort
bubblesortsentinela
combsort
countingsort
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ BINARY?=dummy\
radixsort\
redblacktreesort\
cppsort\
cppmultisetsort\
pqsortsimple\
heapsort\
countingsort\
Expand Down Expand Up @@ -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;\
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions cppmultisetsort.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

já que vamos começar a adicionar mais soluções em C++, seria adequado modificar o cppsort para funcionar da mesma forma que o main.c , melhor ainda se mudar tudo de C++ para ser interoperável com o main.c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certo, vou trabalhar nisso, alguma sugestão de como fazer essa interoperabilidade ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifiquei o cppsort para ficar no padrão, veja os commits relacionados na árvore.

[]s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fiz as alterações pra funcionar de acordo com o padrão do cppsort 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright(C) 2020, Bruno César Ribas <bruno.ribas@unb.br>
*
* 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 <set>

void cppmultisetsort(Item *v, int l, int r) {
std::multiset<Item> st(v + l, v + r + 1);
int i = 0;
for (auto it = st.begin(); it != st.end(); ++it) {
v[l + i++] = *it;
}
}
23 changes: 23 additions & 0 deletions cppmultisetsort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/*
* Copyright(C) 2020, Bruno César Ribas <bruno.ribas@unb.br>
*
* 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
4 changes: 4 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down