bubble sort a character array in alphabetic order in c

前端 未结 5 476
眼角桃花
眼角桃花 2020-12-22 05:24

I\'m trying to bubble sort a character array in alphabetic order. My code is as follows:

#define CLASS_SIZE 10
#include 

void bubbleSortAWrit         


        
5条回答
  •  余生分开走
    2020-12-22 06:05

    Bubble sort

    Console: Input: "face321" OutPut: "123acef"

        #include 
    
    int main(){
    
        char c[80] = "0";
    char temp = '0';
    int offSet = 0;
    int i = 0;
    int j =0;
    int count =0;
    
    printf("Enter first string: ");
    gets(c);
    
    while (*(c + offSet) != '\0') {
        count++;
        offSet++;
    }
    
    
    
    for (i = 0; i < count; i++) {
    for (j = 0; j < count - 1; j++) {
    
    
        if (c[j]>c[j + 1]) {
    
            temp = c[j];
            c[j] = c[j + 1];
            c[j + 1] = temp;
    
        }
    
    }
    
    }
        puts(c);
        return 0;
    }
    

提交回复
热议问题