doraiapp
asked on
sorting
sort(NAME lprod[],int num)
{
int i,j;
for(i=1;i<4;i++)
{
for(j=1;j<=4-i;j++)
{
if(strcmp(lprod[j-1].Name, lprod[j].N ame)>0){
printf("function call j-1=%s, j=%s\n",lprod[j-1].Name,lp rod[j].Nam e);
swap(lprod[j],lprod[j-1]);
}
}
}
for (i=0;i<=3;i++){
printf("sorted =%s\n",lprod[i].Name);}
}
swap(NAME a,NAME b)
{
NAME c;
printf("%s\n",a.Name);
c.No=b.No;strcpy(c.Name,b. Name);c.Ra te=b.Rate; c.Hours=b. Hours;
b.No=a.No;strcpy(b.Name,a. Name);b.Ra te=a.Rate; b.Hours=a. Hours;
a.No=c.No;strcpy(a.Name,c. Name);a.Ra te=c.Rate; a.Hours=c. Hours;
printf("dummy=%s, a=%s,b=%s\n",c.Name,a.Name ,b.Name);
What's wrong with my code i 'm not able to sort it in order?
}
{
int i,j;
for(i=1;i<4;i++)
{
for(j=1;j<=4-i;j++)
{
if(strcmp(lprod[j-1].Name,
printf("function call j-1=%s, j=%s\n",lprod[j-1].Name,lp
swap(lprod[j],lprod[j-1]);
}
}
}
for (i=0;i<=3;i++){
printf("sorted =%s\n",lprod[i].Name);}
}
swap(NAME a,NAME b)
{
NAME c;
printf("%s\n",a.Name);
c.No=b.No;strcpy(c.Name,b.
b.No=a.No;strcpy(b.Name,a.
a.No=c.No;strcpy(a.Name,c.
printf("dummy=%s, a=%s,b=%s\n",c.Name,a.Name
What's wrong with my code i 'm not able to sort it in order?
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
void swap(NAME* a, NAME* b) {
NAME c;
c= *a;
*a= *b;
*b= c;
}
instead of copying all struct members individually?
kind regards,
Jos