Example Shell Sort Schedule C Bahasa Language

Shell sort Also known as the diminishing increment method. This method was developed by Donald L. Shell in 1959, so it is often called the Shell Sort Method. This method sorts the data by comparing a data with other data that has a certain distance, then exchange it if needed.

Shell Sort is a sorting algorithm that is more reliable than Selection Sort and Bubble Sort. Its reliability is: “Dividing the data series into two parts. Each chapter is sorted using Bubble Sort. Do not use iteration but increment. The iteration is done according to the increment value.

The sorting process with Shell sort can be simulated as follows:

First, choose the initial distance from the data to be compared, which is N/2. The first data is compared with data with a distance of N/2. If the first data is greater than the data to N/2, then the two data are exchanged. Then the second data is compared with the same distance, namely N/2. And so on until all data are compared so that all jth data is always smaller than (j + N/2) data.

In the next process, the distance (N/2)/2 or N/4 is used. The first data is compared with data with a distance of N/4. If the first data is greater than the data to N/4 then the two data are exchanged. Then the second data is compared with the same distance, namely N/4. And so on until all data are compared so that all jth data is smaller than (j + N/4) data.

In the next process, the distance (N/4)/2 or N/8 is used. And so on until the distance used is 1.

The Shell method algorithm can be written as follows:

  1. Distance = N
  2. As long as (Distance > 1) work row 3 to 9
  3. Distance = Distance / 2. Already = false
  4. Do lines 4 through 8 as long as Already = false
  5. Already = true
  6. j = 0
  7. As long as (j < N – Distance) work rows 8 and 9
  8. If (Data[j] > Data[j + Jarak] then exchange data[j], Data[j + Jarak], Already = true
  9. j = j + 1

Example of C Language Counting Sort Program
Example of C Language Insertion Sort Program
Example of a Bubble Sort Program in C Bahasa Language
C Language Selection Sort Program Example


Here’s an example of a Shell sort program in C:

Shell Sort Program Example in C Bahasa Language

  also known as increment method C Shell Sort Program Example
Example of a Shell Sort Program in C Bahasa Language

#include “stdio.h”

int main()
{
int L[20],temp,i,j,n=6,m;
printf(“sorting by shell sort nEnter %d elements: n”,n);
for(i=0;i<n;i++){
scanf(“%d”,&L[i]);}

printf(“nbefore sorting: “);

for(i=0;i<n;i++){printf(“%d”,L[i]);}

for(m = n/2;m>0;m/=2){
/*6 7 2 1 ===> 2 7 6 1, 2 1 6 7 // 1 2 6 7, 1 2 6 7, 1 2 6 7*/
for(j=m;j<n;j++){
for(i=m;i>=0;i-=m){
if(L[i+m]>=L[i]) breaks;
else{
temp = L[i];
L[i] = L[i+m];
L[i+m] = temps;
}
}
}
}

printf(“nafter sorting: “);
for(i=0;i<n;i++){printf(“%d”,L[i]);}
printf(“n”);
}

Example of a Shell Sort Program in C Bahasa Language

MARKIJAR: LET’S LEARN

Leave a Reply

Your email address will not be published. Required fields are marked *