Straight insertion is a sorting method which takes a parenthesis data on ordered data and shoves data which is bigger than parenthesis data so parenthesis data can be placed on right place. For example, there is an array that contains these number :
3  12  2  4  13  5 
Parenthesis Data  Sorting Result  
12 
 
2 
 
4 
 
13 
 
5 
 
Result 

For implementation this sorting method, I use C program as an example.
First, I make a file that contains some numbers that will be sorted. I give its name "numberdata.txt". The numbers are separated by space.
Second, I build a source code which is placed in the same folder with "numberdata.txt". I give its name "insertionsort.c"
Here is the program in C.
#include <stdio.h>
#include <stdlib.h>
const int ndata = 12; //number of data that will be sorted
int main()
{
//variables
int array[ndata];
int resultarray[ndata];
//read file "numberdata.txt"
//put the values which is got into an array
FILE *pers;
pers = fopen("numberdata.txt","r");
int m;
for(m=0; m<ndata; m++)
{
fscanf(pers,"%d",&array[m]);
printf("%d\t",array[m]);
}
fclose(pers);
printf("\n");
//put data in array into resultarray
for(m=0; m<ndata; m++)
{
resultarray[m] = array[m];
printf("%d\t",resultarray[m]);
}
printf("\n");
//ascending sort using insertion method
int n,p;
for(m=1; m<ndata; m++)
{
for(n=0; n<m; n++)
{
if (array[m]<resultarray[n])
{
for(p=m; p>n; p)
{
resultarray[p]=resultarray[(p1)];
}
resultarray[n] = array[m];
break;
}
}
}
//show result
for(m=0; m<ndata; m++)
{
printf("%d\t",resultarray[m]);
}
printf("\n");
return 0;
}
#include <stdlib.h>
const int ndata = 12; //number of data that will be sorted
int main()
{
//variables
int array[ndata];
int resultarray[ndata];
//read file "numberdata.txt"
//put the values which is got into an array
FILE *pers;
pers = fopen("numberdata.txt","r");
int m;
for(m=0; m<ndata; m++)
{
fscanf(pers,"%d",&array[m]);
printf("%d\t",array[m]);
}
fclose(pers);
printf("\n");
//put data in array into resultarray
for(m=0; m<ndata; m++)
{
resultarray[m] = array[m];
printf("%d\t",resultarray[m]);
}
printf("\n");
//ascending sort using insertion method
int n,p;
for(m=1; m<ndata; m++)
{
for(n=0; n<m; n++)
{
if (array[m]<resultarray[n])
{
for(p=m; p>n; p)
{
resultarray[p]=resultarray[(p1)];
}
resultarray[n] = array[m];
break;
}
}
}
//show result
for(m=0; m<ndata; m++)
{
printf("%d\t",resultarray[m]);
}
printf("\n");
return 0;
}
https://nextplus.vip/apk/
ReplyDeletehttps://photoshoptouch.xyz/apk/
https://holalauncher.xyz/apk/