Friday, January 22, 2016

ჩასმის მეთოდით დალაგება ზრდადობის მიხედვით C

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
     int i,j,k,c,temp;
   
   int mas[8]= {14,11,8,16,2,12,19,7};
   int n=8;  
 
for(i=0;i<n;i++)
{
                temp=mas[i];
                j=i-1;
                while((temp<mas[j])&& j>=0)
                {
                    mas[j+1]=mas[j];
                    j=j-1;   
                }
                mas[j+1]=temp;
}     
      
    for(i=0;i<n;i++)
     {                    
     printf("%d\n",mas[i]);  
     }
system("pause");
return 0;
}

No comments:

Post a Comment