From fec989a69f19a4c0bc45486ee5666c33e76fdd7a Mon Sep 17 00:00:00 2001 From: AD0naldRavenclow Date: Mon, 24 Apr 2023 12:49:24 +0800 Subject: [PATCH] [HUST CSE][WCH][library] fix error in Bubble Sort (#7240) --- .../StdPeriph_Driver/src/ch32f20x_adc.c | 6 +++--- .../StdPeriph_Driver/src/ch32v10x_adc.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bsp/wch/arm/Libraries/CH32F20x_StdPeriph_Driver/StdPeriph_Driver/src/ch32f20x_adc.c b/bsp/wch/arm/Libraries/CH32F20x_StdPeriph_Driver/StdPeriph_Driver/src/ch32f20x_adc.c index e03286d595..1ff20df4b9 100644 --- a/bsp/wch/arm/Libraries/CH32F20x_StdPeriph_Driver/StdPeriph_Driver/src/ch32f20x_adc.c +++ b/bsp/wch/arm/Libraries/CH32F20x_StdPeriph_Driver/StdPeriph_Driver/src/ch32f20x_adc.c @@ -1071,12 +1071,12 @@ int16_t Get_CalibrationValue(ADC_TypeDef* ADCx) buf[i] = ADCx->RDATAR; } - for(i=0; i<10; i++){ - for(j=0; j<10; j++){ + for(i=0; i<9; i++){ + for(j=0; j<9-i; j++){ if(buf[j]>buf[j+1]){ t=buf[j]; buf[j]=buf[j+1]; - buf[j]= t; + buf[j+1]= t; } } } diff --git a/bsp/wch/risc-v/Libraries/CH32V10x_StdPeriph_Driver/StdPeriph_Driver/src/ch32v10x_adc.c b/bsp/wch/risc-v/Libraries/CH32V10x_StdPeriph_Driver/StdPeriph_Driver/src/ch32v10x_adc.c index b5d2998bdd..9f67eac792 100644 --- a/bsp/wch/risc-v/Libraries/CH32V10x_StdPeriph_Driver/StdPeriph_Driver/src/ch32v10x_adc.c +++ b/bsp/wch/risc-v/Libraries/CH32V10x_StdPeriph_Driver/StdPeriph_Driver/src/ch32v10x_adc.c @@ -1124,12 +1124,12 @@ int16_t Get_CalibrationValue(ADC_TypeDef *ADCx) buf[i] = ADCx->RDATAR; } - for(i = 0; i < 10; i++){ - for(j = 0; j < 10; j++){ + for(i = 0; i < 9; i++){ + for(j = 0; j < 9 - i; j++){ if(buf[j] > buf[j + 1]){ t = buf[j]; buf[j] = buf[j + 1]; - buf[j] = t; + buf[j + 1] = t; } } }