/** * Created by Vijay Yalasangimath on 23-02-2016. * Non lexicographical order sorting */ #include<stdio.h> #include<string.h> /** * returns 0 when both strings are equal * + str1 < str2 (In provided order) * - str1 > str2 (In provided order) */ long int mySort(char *a , char *b){ long int c1,c2; char * myLex = "qwertyuiopasdfghjklzxcvbnm"; char *p1,*p2; p1=strchr(myLex, *a); p2=strchr(myLex, *b); c1=p1-myLex+1; c2=p2-myLex+1; while((a[0]!='\0'||b[0]!='\0')&&(c1==c2)){ p1=strchr(myLex, *a); p2=strchr(myLex, *b); c1=p1-myLex+1; c2=p2-myLex+1; a++; b++; } return c2-c1; } int main(){ char str1[25],str2[25]; printf("String will be compared in following order: qwertyuiopasdfghjklzxcvbnm\n"); printf("Enter the strings for comparison\n"); printf("First string:"); scanf("%s",str1); printf("Second string:"); scanf("%s",str2); printf("%ld\n", mySort(str1,str2)); return 0; }
Goal of this blog is to provide programming material to beginners. At present this blog contains the stuff related to C programming and Data structures with C like mini-projects codes ,some simple C codes and tutorials. (use Google chrome to browse this blog) HAPPY PROGRAMMING!!
Monday, 22 February 2016
Non lexicographical order sorting
Subscribe to:
Posts (Atom)