int strcmp(const char *leftStr, const char *rightStr );
("Sam", "Alice") returns a negative value (b.c. "Sam"<"alice" i.e.="" "sam"="" is="" shorter="" than="" "alice")="" ("alice",="" "sam")="" returns="" a="" positive="" value="" (b.c.="" "alice"="">"Sam" i.e. "Alice" is longer than "Sam") ("Sam", "Tom") returns a negative value (b.c. "Sam" < "tom"="" i.e.="" they="" have="" the="" same="" length="" but=""><"tom" by="" strcmp)="" ("tom",="" "sam")="" returns="" a="" positive="" value="" (b.c.="" "tom"=""> "Sam" i.e. they have the same length but "Tom">"Sam" by strcmp) ("Tom", "Tom") returns 0 (b.c. "Tom" == "Sam" i.e. they have the same length and "Tom"=="Sam" by strcmp)"tom">"alice">
int comp_greater(const char *leftStr, const char *rightStr ){ return -strcmp(leftStr, rightStr); }
printf("\n Data is loaded"); printf("\n Allocated space for storing the data: %7d B ( %d char and %d pointers)",size_in_bytes, allocated, n); printf("\n Pointer size: %d Bytes\n", sizeof(void*)); printf("\nOriginal data: \n"); print_data(table, n); printf("\n-------- compare by LENGTH only --------------\n"); insertion_sort_ptr(table, n, comp_length); print_data(table, n); printf("\n-------- compare by strcmp --------------\n"); insertion_sort_ptr(table, n, strcmp); // here strcmp is the one from the C-library (NOT implemented by me) print_data(table, n); printf("\n-------- compare by GREATER --------------\n"); insertion_sort_ptr(table, n, comp_greater); print_data(table, n); printf("\n-------- compare by LENGTH and lexicografic --------------\n"); insertion_sort_ptr(table, n, comp_mixt); print_data(table, n); free_table(table, n);
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here