-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2. String-Sorting.c
44 lines (41 loc) · 861 Bytes
/
2. String-Sorting.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<string.h>
void selection_sort(char s[]){
char temp;
int l,i,j,min;
l=strlen(s);
for(i=0;i<l-1;i++){
min=i;
for(j=i+1;j<l;j++){
if(s[j]<s[min]){
min=j;
}
}
temp=s[min];
s[min]=s[i];
s[i]=temp;
}
printf("\nThe Sorted Array is(Selection Sort) : %s",s);
}
void insertion_sort(char s[]){
int i,j,l;
char temp;
l=strlen(s);
for(i=1;i<l;i++){
temp=s[i];
j=i-1;
while(j>=0&&s[j]>temp){
s[j+1]=s[j];
j--;
}
s[j+1]=temp;
}
printf("The Sorted Array is(Insertion sort) : %s",s);
}
int main(){
char s[200];
printf("Enter the Character array :");
scanf("%s",s);
insertion_sort(s);
selection_sort(s);
}