Tuesday, 23 September 2014

Hackerrank Correctness and the Loop Invariant Solution

The Solution for hackerrank problem, Correctness and the Loop Invariant using C Program.
Passed Test cases: 3 out of 3

SOURCE CODE:


 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 #include <assert.h>  
 #include <stddef.h>  
 void insertionSort(int ar_size, int * ar) {    
   int i,j;  
   int value;  
   for(i=1;i<ar_size;i++)  
   {  
     value=ar[i];  
     j=i-1;  
     while(j>=0 && value<ar[j])  
     {  
       ar[j+1]=ar[j];  
       j=j-1;  
     }  
     ar[j+1]=value;      
   }  
   for(j=0;j<ar_size;j++)  
     {  
       printf("%d",ar[j]);  
       printf(" ");  
     }  
 }  
 int main(void) {    
   int _ar_size;  
 scanf("%d", &_ar_size);  
 int _ar[_ar_size], _ar_i;  
 for(_ar_i = 0; _ar_i < _ar_size; _ar_i++) {   
   scanf("%d", &_ar[_ar_i]);   
 }  
 insertionSort(_ar_size, _ar);  
   return 0;  
 }  

4 comments:

  1. Correctness in everything is really important in our lives. We can learn to do things in a perfec t way as we do essay writing service reviews work perfectly. Thios blog is really a best and productive blog in this regard.

    ReplyDelete
  2. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Without have account on instagram we can see more nice great stories with my site.

    ReplyDelete
  3. I am interested in this topic and would like to find out some more information as my friend need information on this topic. Do you have any other articles about this. Thanks for the great information. Get seo training from PassBraindump Exams

    ReplyDelete
  4. frases de buenos dias Actually its very nice site! this is my first visit on this site my friend gave the link of this site! and site is really great

    ReplyDelete