#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct Node
{
char * rune;
int val;
}node;
int cmp_str(const void*a,const void *b)
{
return strcmp((char*)a,(char*)b);
}
int cmp(const void*a,const void *b)
{
return *(int *)a>*(int*)b ?1:-1;
}
int cmp_compare(const void*a,const void *b)
{
node *a_= (node*)a;
node *b_= (node*)b;
if ( strcmp(a_->rune,b_->rune) < 0 )
return -1;
else if ( strcmp(a_->rune,b_->rune) > 0 )
return 1;
else
return a_->val-b_->val ;
}
void PRINT_ELEM(char **a,int n)
{
for(int i=0;i<n;i++)
{
printf("%s\n",*(a+i));
}
}
int main()
{
char *a[5]={"abd","ddi","dda","aba","byd"};
int b[5]={6,6,6,8,6};
node c[5];
for(int i=0;i<5;i++)
{
c[i].val=b[i];c[i].rune=a[i];
printf("%s || %d\n",c[i].rune,c[i].val);
}
qsort(c,5,sizeof(c[0]),cmp_compare);
for(int i=0;i<5;i++)
{
printf("%s || %d\n",c[i].rune,c[i].val);
}
}