Created
October 12, 2014 18:30
-
-
Save yorickdewid/0f123979a43f1abe501a to your computer and use it in GitHub Desktop.
Example of lexicographical ordering in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char *argv[]){ | |
int i,j; | |
char str[10][50], temp[50]; | |
printf("Enter 10 words:\n"); | |
for(i=0;i<10;++i) | |
gets(str[i]); | |
for(i=0;i<9;++i) | |
for(j=i+1;j<10 ;++j){ | |
if(strcmp(str[i],str[j])>0){ | |
strcpy(temp,str[i]); | |
strcpy(str[i],str[j]); | |
strcpy(str[j],temp); | |
} | |
printf("In lexicographical order: \n"); | |
for(i=0;i<10;++i){ | |
puts(str[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment