clanguage07@gmail.com

clanguage07@gmail.com

Sunday, September 8, 2013

sorting of array using pointer in c

sorting of array using pointer in c

int main(){
   int  i,j,temp1,temp2;
   int arr[8]={5,3,0,2,12,1,33,2};
   int *ptr;
   for(i=0;i<7;i++){
     for(j=0;j<7-i;j++){
if(*(arr+j)>*(arr+j+1)){
        ptr=arr+j;
        temp1=*ptr++;
        temp2=*ptr;
        *ptr--=temp1;
        *ptr=temp2;
}
      }
   }

   for(i=0;i<8;i++)
     printf(" %d",arr[i]);
}

Output: 0 1 2 2 3 5 12 33

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true