C with classes
This commit is contained in:
30
C/BasicSyntax/Pointer/work_21.cpp
Normal file
30
C/BasicSyntax/Pointer/work_21.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
void sort(int *arr,int m){
|
||||
bool flag = false;
|
||||
while(flag == false){
|
||||
int js=0;
|
||||
for(int i = 0; i < m-1; i++){
|
||||
if(*(arr+i)>*(arr+i+1)){
|
||||
int temp;
|
||||
temp = *(arr+i+1);
|
||||
* (arr+i+1) = * (arr+i);
|
||||
* (arr+i) = temp;
|
||||
js++;
|
||||
}
|
||||
}
|
||||
if(js==0) flag=true;
|
||||
}
|
||||
}
|
||||
int main(){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
int a[n];
|
||||
for(int i = 0; i < n; i++){
|
||||
scanf("%d",&a[i]);
|
||||
}
|
||||
sort(a,n);
|
||||
for(int i = 0; i < n; i++){
|
||||
printf("%d ",a[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user