I have this struct:
typedef struct data{
char name[100], pseudo[100];
int num0, num1, num2, num3, num4;
long int lnum0, lnum1, lnum2, lnum3, lnum4;
double dnum0, dnum1;
}data;
data list[50]
I create an array of this struct and sort them with a quicksort algorithm. To do that I must swap element using this function:
void swap(data list[], i, j){
data tmp;
tmp.num1 = list[i].num1
list[i].num1 = list[j].num1
list[j].num1 =tmp.num1
//using memmove to avoid overlaping from the strcpy function
memmove(temp.name,list[i].name,strlen(list[i].name));
memmove(list[i].name,list[j].name,strlen(list[j].num1));
memmove(list[j].name,tmp.name,strlen(tmp.name));
}
I have 16 element in my struct, and i have to repeat 16 times this function to swap them all. My question is : Is there another simpler,faster or nicer way to proceed, or can we optimize this function ?