Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- void bubble(int vetor[],int n);
- int main(){
- int *vec,size,count;
- printf("insira o tamanho do vetor a ser ordenado: ");
- scanf("%d",&size);
- vec = (int *) malloc(sizeof(int)*size);
- for (count =0;count < size; count ++){
- printf("\nDigite a posição %d do vetor: ",count+1);
- scanf("%d",&vec[count]);
- }
- printf("\nVETOR DESORDENADO: \n");
- for (count =0;count < size; count ++){
- printf("\nvec[%d]: %d",count+1,vec[count]);
- }
- bubble(vec,size);
- printf("\nVETOR ORDENADO: \n");
- for (count =0;count < size; count ++){
- printf("\nvec[%d]: %d",count+1,vec[count]);
- }
- return 0;
- }
- void bubble(int vetor[],int n){
- int k = n-1,aux,i,j;
- for(i=0;i<n;i++){
- for(j=0;j<k;j++){
- if(vetor[j] > vetor[j+1]){
- aux = vetor[j];
- vetor[j] = vetor [j+1];
- vetor[j+1] = aux;
- }
- }
- k--;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement