Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [c] pascal --> C (bubblesort)

    qualcuno mi traduce questo allegato, x favore? :quipy:

    ... mi servirebbe anke il main ke kiama la procedura... :quipy:

    @@@

  2. #2
    esiste anche il motore di ricerca: Bubble Sort

    ...completo:
    codice:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int vet[10] = {2, 1, 0, 6, 9, 5, 8, 7, 3, 4};
        int i, j, temp;
        
        for(i = 0; i < 10; i++)
            printf("%d ", vet[i]);
            
        for(i = 0; i < 9; i++)
            for(j = i + 1; j < 10; j++)
                if(vet[j] < vet[i])
                {
    	        temp = vet[i];
    	        vet[i] = vet[j];
    	        vet[j] = temp;
      	    }
        
        printf("\n");
        
        for(i = 0; i < 10; i++)
            printf("%d ", vet[i]);
            
        printf("\n");
        system("pause");
        return 0;
    }
    ...Terrible warlords, good warlords, and an english song

  3. #3
    Utente di HTML.it L'avatar di infinitejustice
    Registrato dal
    Nov 2001
    residenza
    Barcelona
    Messaggi
    772
    Questa è la seconda versione del Bubble. Nel caso migliore la complessità diventa n

    codice:
    void bubblesort(int *myArray, int nr){
    
    	int i, j, limit = nr, temp;
    
    	while(limit){
    			for(i = 0, j = 0; i < limit -1; i++){
    				if(*(myArray+i) > *(myArray+(i + 1))){
    					temp = *(myArray+i);
    					*(myArray+i) = *(myArray+(i + 1));
    					*(myArray+(i + 1)) = temp;
    					j = i+1;
    					}
    				}
    			limit = j;
    		}
    }
    Live fast. Troll hard.
    Pythonist | Djangonaut | Puppeteer | DevOps | OpenStacker | Lost in malloc
    Team Lead @Gameloft Barcelona

  4. #4
    G R A Z I E - 1 0 0 0 !!!


    @@@

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.