Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*BUBBLE SORT PARA PDIS E LOCAIS (POR ORDEM ALFABETICA E POR N INSCRITOS)*/
- void ordena_pdis(lista_locais auxLocais,int flag){
- lista_locais l = auxLocais;
- while(l){
- lista_pdi d = l->lista_pdi_local;
- int n_nos=0;
- n_nos = nNosPdi(d);
- if(flag==0){
- bubbleSortPdi(&d,n_nos,0);
- }else{
- bubbleSortPdi(&d,n_nos,1);
- }
- l=l->next;
- }
- }
- lista_locais trocaNos(lista_locais ptr1, lista_locais ptr2)
- {
- lista_locais tmp = ptr2->next;
- ptr2->next = ptr1;
- ptr1->next = tmp;
- return ptr2;
- }
- lista_pdi trocaNosPdi(lista_pdi ptr1, lista_pdi ptr2)
- {
- lista_pdi tmp = ptr2->next;
- ptr2->next = ptr1;
- ptr1->next = tmp;
- return ptr2;
- }
- int nNos(lista_locais head)
- {
- int count = 0;
- lista_locais atual = head;
- while (atual != NULL)
- {
- count++;
- atual = atual->next;
- }
- return count;
- }
- int nNosPdi(lista_pdi head)
- {
- int count = 0;
- lista_pdi atual = head;
- while (atual != NULL)
- {
- count++;
- atual = atual->next;
- }
- return count;
- }
- void bubbleSort(lista_locais * head, int count,int flag)
- {
- lista_locais* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_locais p1 = *h;
- lista_locais p2 = p1->next;
- if(flag==0){
- if (p1->n_inscritos_local > p2->n_inscritos_local) {
- *h = trocaNos(p1, p2);
- troca = 1;
- }
- }else{
- if (strcmp(p1->nome,p2->nome)>0){
- *h = trocaNos(p1, p2);
- troca = 1;
- }
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- void bubbleSortPdi(lista_pdi * head, int count,int flag)
- {
- lista_pdi* h;
- int i, j, troca;
- for (i = 0; i <= count; i++) {
- h = head;
- troca = 0;
- for (j = 0; j < count - i - 1; j++) {
- lista_pdi p1 = *h;
- lista_pdi p2 = p1->next;
- if(flag==0){
- if (p1->n_inscritos_pdi > p2->n_inscritos_pdi) {
- *h = trocaNosPdi(p1, p2);
- troca = 1;
- }
- }else{
- if (strcmp(p1->nome,p2->nome)>0) {
- *h = trocaNosPdi(p1, p2);
- troca = 1;
- }
- }
- h = &(*h)->next;
- }
- if (troca == 0)
- break;
- }
- }
- /*FIM DAS FUNCOES PARA O SORT*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement