-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlexical-order-sorting.c
36 lines (30 loc) · 979 Bytes
/
lexical-order-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
#include<stdio.h>
#include<string.h>
int main(){
int i = 0, j = 0;
char element[10][32] = {"Abraham Lincoln", "Mother Teresa", "Martin Luther King",
"Nelson Mandela", "Muhammad Ali", "Mahatma Gandhi",
"Winston Churchill ", "Christopher Columbus", "Charles Darwin",
"Neil Armstrong"}; // 10 element of 32 bit
char temp[32];
printf("Normal Order: \n");
for(i = 0; i < 10; i++){
printf("\n%s", element[i]);
}
for(i = 0; i < 10; i++){
for(j = i+1; j < 10; j++){
if(strcmp(element[i], element[j]) > 0){
// Swap String
strcpy(temp, element[i]);
strcpy(element[i], element[j]);
strcpy(element[j], temp);
}
}
}
printf("\n\nLexical Order: \n");
for(i = 0; i < 10; i++){
printf("\n%s", element[i]);
}
printf("\n");
return 0;
}