SlideShare a Scribd company logo
1 of 10
Download to read offline
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf("Enter the number of elements : ");
scanf("%d",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf("Increment=%d  ",incr);
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf(" ");
incr=incr-2; /*Decrease the increment*/
}/*End of while*/
printf("Sorted list is : ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf(" ");
}/*End of main()*/
redix sort
/*Program of sorting using radix sort*/
# include
# include
struct node
{
int info ;
struct node *link;
}*start=NULL;
main()
{
struct node *tmp,*q;
int i,n,item;
printf("Enter the number of elements in the list : ");
scanf("%d", &n);
for(i=0;iinfo=item;
tmp->link=NULL;
if(start==NULL) /* Inserting first element */
start=tmp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of for*/
printf("Unsorted list is : ");
display();
radix_sort();
printf("Sorted list is : ");
display ();
}/*End of main()*/
display()
{
struct node *p=start;
while( p !=NULL)
{
printf("%d ", p->info);
p= p->link;
}
printf(" ");
}/*End of display()*/
radix_sort()
{
int i,k,dig,maxdig,mindig,least_sig,most_sig;
struct node *p, *rear[10], *front[10];
least_sig=1;
most_sig=large_dig(start);
for(k = least_sig; k <= most_sig ; k++)
{
printf("PASS %d : Examining %dth digit from right ",k,k);
for(i = 0 ; i <= 9 ; i++)
{
rear[i] = NULL;
front[i] = NULL ;
}
maxdig=0;
mindig=9;
p = start ;
while( p != NULL)
{
/*Find kth digit in the number*/
dig = digit(p->info, k);
if(dig>maxdig)
maxdig=dig;
if(diglink = p ;
rear[dig] = p ;
p=p->link;/*Go to next number in the list*/
}/*End while */
/* maxdig and mindig are the maximum amd minimum
digits of the kth digits of all the numbers*/
printf("mindig=%d maxdig=%d ",mindig,maxdig);
/*Join all the queues to form the new linked list*/
start=front[mindig];
for(i=mindig;ilink=front[i+1];
else
rear[i+1]=rear[i];
}
rear[maxdig]->link=NULL;
printf("New list : ");
display();
}/* End for */
}/*End of radix_sort*/
/* This function finds number of digits in the largest element of the list */
int large_dig()
{
struct node *p=start ;
int large = 0,ndig = 0 ;
while(p != NULL)
{
if(p ->info > large)
large = p->info;
p = p->link ;
}
printf("Largest Element is %d , ",large);
while(large != 0)
{
ndig++;
large = large/10 ;
}
printf("Number of digits in it are %d ",ndig);
return(ndig);
} /*End of large_dig()*/
/*This function returns kth digit of a number*/
int digit(int number, int k)
{
int digit, i ;
for(i = 1 ; i <=k ; i++)
{
digit = number % 10 ;
number = number /10 ;
}
return(digit);
}/*End of digit()*/
Solution
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf("Enter the number of elements : ");
scanf("%d",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf("Increment=%d  ",incr);
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf(" ");
incr=incr-2; /*Decrease the increment*/
}/*End of while*/
printf("Sorted list is : ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf(" ");
}/*End of main()*/
redix sort
/*Program of sorting using radix sort*/
# include
# include
struct node
{
int info ;
struct node *link;
}*start=NULL;
main()
{
struct node *tmp,*q;
int i,n,item;
printf("Enter the number of elements in the list : ");
scanf("%d", &n);
for(i=0;iinfo=item;
tmp->link=NULL;
if(start==NULL) /* Inserting first element */
start=tmp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of for*/
printf("Unsorted list is : ");
display();
radix_sort();
printf("Sorted list is : ");
display ();
}/*End of main()*/
display()
{
struct node *p=start;
while( p !=NULL)
{
printf("%d ", p->info);
p= p->link;
}
printf(" ");
}/*End of display()*/
radix_sort()
{
int i,k,dig,maxdig,mindig,least_sig,most_sig;
struct node *p, *rear[10], *front[10];
least_sig=1;
most_sig=large_dig(start);
for(k = least_sig; k <= most_sig ; k++)
{
printf("PASS %d : Examining %dth digit from right ",k,k);
for(i = 0 ; i <= 9 ; i++)
{
rear[i] = NULL;
front[i] = NULL ;
}
maxdig=0;
mindig=9;
p = start ;
while( p != NULL)
{
/*Find kth digit in the number*/
dig = digit(p->info, k);
if(dig>maxdig)
maxdig=dig;
if(diglink = p ;
rear[dig] = p ;
p=p->link;/*Go to next number in the list*/
}/*End while */
/* maxdig and mindig are the maximum amd minimum
digits of the kth digits of all the numbers*/
printf("mindig=%d maxdig=%d ",mindig,maxdig);
/*Join all the queues to form the new linked list*/
start=front[mindig];
for(i=mindig;ilink=front[i+1];
else
rear[i+1]=rear[i];
}
rear[maxdig]->link=NULL;
printf("New list : ");
display();
}/* End for */
}/*End of radix_sort*/
/* This function finds number of digits in the largest element of the list */
int large_dig()
{
struct node *p=start ;
int large = 0,ndig = 0 ;
while(p != NULL)
{
if(p ->info > large)
large = p->info;
p = p->link ;
}
printf("Largest Element is %d , ",large);
while(large != 0)
{
ndig++;
large = large/10 ;
}
printf("Number of digits in it are %d ",ndig);
return(ndig);
} /*End of large_dig()*/
/*This function returns kth digit of a number*/
int digit(int number, int k)
{
int digit, i ;
for(i = 1 ; i <=k ; i++)
{
digit = number % 10 ;
number = number /10 ;
}
return(digit);
}/*End of digit()*/

More Related Content

Similar to Program of sorting using shell sort #include stdio.h #de.pdf

There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxclarkjanyce
 
C basics
C basicsC basics
C basicsMSc CST
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ Eli Diaz
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ Eli Diaz
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxGordonpACKellyb
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfANJALIENTERPRISES1
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxgordienaysmythe
 

Similar to Program of sorting using shell sort #include stdio.h #de.pdf (20)

Vcs29
Vcs29Vcs29
Vcs29
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
C basics
C basicsC basics
C basics
 
Lab Question
Lab QuestionLab Question
Lab Question
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
 
Cquestions
Cquestions Cquestions
Cquestions
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
week-5x
week-5xweek-5x
week-5x
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
week-16x
week-16xweek-16x
week-16x
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
i am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdfi am using C++ codingsource coding Program that sorts an arra.pdf
i am using C++ codingsource coding Program that sorts an arra.pdf
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 

More from anujmkt

It is used as the solvent .pdf
                     It is used as the solvent                        .pdf                     It is used as the solvent                        .pdf
It is used as the solvent .pdfanujmkt
 
molality = mole wt of solvent 0.11 = mole 21.pdf
                     molality = mole  wt of solvent  0.11 = mole  21.pdf                     molality = mole  wt of solvent  0.11 = mole  21.pdf
molality = mole wt of solvent 0.11 = mole 21.pdfanujmkt
 
NaF would be having highest melting point because.pdf
                     NaF would be having highest melting point because.pdf                     NaF would be having highest melting point because.pdf
NaF would be having highest melting point because.pdfanujmkt
 
The four bases in DNA are Adenine, Guanine, Cytos.pdf
                     The four bases in DNA are Adenine, Guanine, Cytos.pdf                     The four bases in DNA are Adenine, Guanine, Cytos.pdf
The four bases in DNA are Adenine, Guanine, Cytos.pdfanujmkt
 
b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf
                     b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf                     b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf
b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdfanujmkt
 
CO3 Sol.pdf
                     CO3                                       Sol.pdf                     CO3                                       Sol.pdf
CO3 Sol.pdfanujmkt
 
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdf
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdfNumber of moles of Calcium = 0.05Number of equivalents of calcium .pdf
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdfanujmkt
 
A) d B) a, b, c Solution .pdf
                     A) d B) a, b, c  Solution                    .pdf                     A) d B) a, b, c  Solution                    .pdf
A) d B) a, b, c Solution .pdfanujmkt
 
While doing capital investment, CFO analyze all the risk related to .pdf
While doing capital investment, CFO analyze all the risk related to .pdfWhile doing capital investment, CFO analyze all the risk related to .pdf
While doing capital investment, CFO analyze all the risk related to .pdfanujmkt
 
What is Network security, or Securiing your data Through Network,N.pdf
What is Network security, or Securiing your data Through Network,N.pdfWhat is Network security, or Securiing your data Through Network,N.pdf
What is Network security, or Securiing your data Through Network,N.pdfanujmkt
 
TrueClay it the important of soil for holding plant nutrients in t.pdf
TrueClay it the important of soil for holding plant nutrients in t.pdfTrueClay it the important of soil for holding plant nutrients in t.pdf
TrueClay it the important of soil for holding plant nutrients in t.pdfanujmkt
 
The statement is FalseOnly single target target agents are sunject.pdf
The statement is FalseOnly single target target agents are sunject.pdfThe statement is FalseOnly single target target agents are sunject.pdf
The statement is FalseOnly single target target agents are sunject.pdfanujmkt
 
The reactants along with the oxidation states are Zn = 0 CuSO4.pdf
The reactants along with the oxidation states are Zn = 0 CuSO4.pdfThe reactants along with the oxidation states are Zn = 0 CuSO4.pdf
The reactants along with the oxidation states are Zn = 0 CuSO4.pdfanujmkt
 
The scanner performs lexical analysis of a precise program (in our c.pdf
The scanner performs lexical analysis of a precise program (in our c.pdfThe scanner performs lexical analysis of a precise program (in our c.pdf
The scanner performs lexical analysis of a precise program (in our c.pdfanujmkt
 
Solution Pseudoextinction refers to- D) a species evolving to t.pdf
Solution Pseudoextinction refers to- D) a species evolving to t.pdfSolution Pseudoextinction refers to- D) a species evolving to t.pdf
Solution Pseudoextinction refers to- D) a species evolving to t.pdfanujmkt
 
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdf
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdfShare Holders Equity = Current Assets + Net Fixed Assets - Current.pdf
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdfanujmkt
 
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdf
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdfThe correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdf
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdfanujmkt
 
solimportance for an organization to implement an enterprise system.pdf
solimportance for an organization to implement an enterprise system.pdfsolimportance for an organization to implement an enterprise system.pdf
solimportance for an organization to implement an enterprise system.pdfanujmkt
 
We use the complementation principle. Clearly the.pdf
                     We use the complementation principle. Clearly the.pdf                     We use the complementation principle. Clearly the.pdf
We use the complementation principle. Clearly the.pdfanujmkt
 
right idea but numbers are wrong all over the placeSolution.pdf
right idea but numbers are wrong all over the placeSolution.pdfright idea but numbers are wrong all over the placeSolution.pdf
right idea but numbers are wrong all over the placeSolution.pdfanujmkt
 

More from anujmkt (20)

It is used as the solvent .pdf
                     It is used as the solvent                        .pdf                     It is used as the solvent                        .pdf
It is used as the solvent .pdf
 
molality = mole wt of solvent 0.11 = mole 21.pdf
                     molality = mole  wt of solvent  0.11 = mole  21.pdf                     molality = mole  wt of solvent  0.11 = mole  21.pdf
molality = mole wt of solvent 0.11 = mole 21.pdf
 
NaF would be having highest melting point because.pdf
                     NaF would be having highest melting point because.pdf                     NaF would be having highest melting point because.pdf
NaF would be having highest melting point because.pdf
 
The four bases in DNA are Adenine, Guanine, Cytos.pdf
                     The four bases in DNA are Adenine, Guanine, Cytos.pdf                     The four bases in DNA are Adenine, Guanine, Cytos.pdf
The four bases in DNA are Adenine, Guanine, Cytos.pdf
 
b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf
                     b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf                     b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf
b) HNO2,NO2^+ as when H+ will leave then NO2- wil.pdf
 
CO3 Sol.pdf
                     CO3                                       Sol.pdf                     CO3                                       Sol.pdf
CO3 Sol.pdf
 
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdf
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdfNumber of moles of Calcium = 0.05Number of equivalents of calcium .pdf
Number of moles of Calcium = 0.05Number of equivalents of calcium .pdf
 
A) d B) a, b, c Solution .pdf
                     A) d B) a, b, c  Solution                    .pdf                     A) d B) a, b, c  Solution                    .pdf
A) d B) a, b, c Solution .pdf
 
While doing capital investment, CFO analyze all the risk related to .pdf
While doing capital investment, CFO analyze all the risk related to .pdfWhile doing capital investment, CFO analyze all the risk related to .pdf
While doing capital investment, CFO analyze all the risk related to .pdf
 
What is Network security, or Securiing your data Through Network,N.pdf
What is Network security, or Securiing your data Through Network,N.pdfWhat is Network security, or Securiing your data Through Network,N.pdf
What is Network security, or Securiing your data Through Network,N.pdf
 
TrueClay it the important of soil for holding plant nutrients in t.pdf
TrueClay it the important of soil for holding plant nutrients in t.pdfTrueClay it the important of soil for holding plant nutrients in t.pdf
TrueClay it the important of soil for holding plant nutrients in t.pdf
 
The statement is FalseOnly single target target agents are sunject.pdf
The statement is FalseOnly single target target agents are sunject.pdfThe statement is FalseOnly single target target agents are sunject.pdf
The statement is FalseOnly single target target agents are sunject.pdf
 
The reactants along with the oxidation states are Zn = 0 CuSO4.pdf
The reactants along with the oxidation states are Zn = 0 CuSO4.pdfThe reactants along with the oxidation states are Zn = 0 CuSO4.pdf
The reactants along with the oxidation states are Zn = 0 CuSO4.pdf
 
The scanner performs lexical analysis of a precise program (in our c.pdf
The scanner performs lexical analysis of a precise program (in our c.pdfThe scanner performs lexical analysis of a precise program (in our c.pdf
The scanner performs lexical analysis of a precise program (in our c.pdf
 
Solution Pseudoextinction refers to- D) a species evolving to t.pdf
Solution Pseudoextinction refers to- D) a species evolving to t.pdfSolution Pseudoextinction refers to- D) a species evolving to t.pdf
Solution Pseudoextinction refers to- D) a species evolving to t.pdf
 
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdf
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdfShare Holders Equity = Current Assets + Net Fixed Assets - Current.pdf
Share Holders Equity = Current Assets + Net Fixed Assets - Current.pdf
 
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdf
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdfThe correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdf
The correct answer for m_1=2 is 2,3 for lSolutionThe corre.pdf
 
solimportance for an organization to implement an enterprise system.pdf
solimportance for an organization to implement an enterprise system.pdfsolimportance for an organization to implement an enterprise system.pdf
solimportance for an organization to implement an enterprise system.pdf
 
We use the complementation principle. Clearly the.pdf
                     We use the complementation principle. Clearly the.pdf                     We use the complementation principle. Clearly the.pdf
We use the complementation principle. Clearly the.pdf
 
right idea but numbers are wrong all over the placeSolution.pdf
right idea but numbers are wrong all over the placeSolution.pdfright idea but numbers are wrong all over the placeSolution.pdf
right idea but numbers are wrong all over the placeSolution.pdf
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Program of sorting using shell sort #include stdio.h #de.pdf

  • 1. /* Program of sorting using shell sort */ #include #define MAX 20 main() { int arr[MAX], i,j,k,n,incr; printf("Enter the number of elements : "); scanf("%d",&n); for(i=0;i=1) { for(j=incr;j= 0 && k < arr[i]; i = i-incr) arr[i+incr]=arr[i]; arr[i+incr]=k; } printf("Increment=%d ",incr); for (i = 0; i < n; i++) printf("%d ", arr[i]); printf(" "); incr=incr-2; /*Decrease the increment*/ }/*End of while*/ printf("Sorted list is : "); for (i = 0; i < n; i++) printf("%d ", arr[i]); printf(" "); }/*End of main()*/ redix sort
  • 2. /*Program of sorting using radix sort*/ # include # include struct node { int info ; struct node *link; }*start=NULL; main() { struct node *tmp,*q; int i,n,item; printf("Enter the number of elements in the list : "); scanf("%d", &n); for(i=0;iinfo=item; tmp->link=NULL; if(start==NULL) /* Inserting first element */ start=tmp; else { q=start; while(q->link!=NULL) q=q->link; q->link=tmp; } }/*End of for*/ printf("Unsorted list is : "); display(); radix_sort(); printf("Sorted list is : ");
  • 3. display (); }/*End of main()*/ display() { struct node *p=start; while( p !=NULL) { printf("%d ", p->info); p= p->link; } printf(" "); }/*End of display()*/ radix_sort() { int i,k,dig,maxdig,mindig,least_sig,most_sig; struct node *p, *rear[10], *front[10]; least_sig=1; most_sig=large_dig(start); for(k = least_sig; k <= most_sig ; k++) { printf("PASS %d : Examining %dth digit from right ",k,k); for(i = 0 ; i <= 9 ; i++) { rear[i] = NULL; front[i] = NULL ; } maxdig=0; mindig=9; p = start ; while( p != NULL) { /*Find kth digit in the number*/
  • 4. dig = digit(p->info, k); if(dig>maxdig) maxdig=dig; if(diglink = p ; rear[dig] = p ; p=p->link;/*Go to next number in the list*/ }/*End while */ /* maxdig and mindig are the maximum amd minimum digits of the kth digits of all the numbers*/ printf("mindig=%d maxdig=%d ",mindig,maxdig); /*Join all the queues to form the new linked list*/ start=front[mindig]; for(i=mindig;ilink=front[i+1]; else rear[i+1]=rear[i]; } rear[maxdig]->link=NULL; printf("New list : "); display(); }/* End for */ }/*End of radix_sort*/ /* This function finds number of digits in the largest element of the list */ int large_dig() { struct node *p=start ; int large = 0,ndig = 0 ; while(p != NULL) { if(p ->info > large) large = p->info; p = p->link ; } printf("Largest Element is %d , ",large);
  • 5. while(large != 0) { ndig++; large = large/10 ; } printf("Number of digits in it are %d ",ndig); return(ndig); } /*End of large_dig()*/ /*This function returns kth digit of a number*/ int digit(int number, int k) { int digit, i ; for(i = 1 ; i <=k ; i++) { digit = number % 10 ; number = number /10 ; } return(digit); }/*End of digit()*/ Solution /* Program of sorting using shell sort */ #include #define MAX 20 main() { int arr[MAX], i,j,k,n,incr; printf("Enter the number of elements : ");
  • 6. scanf("%d",&n); for(i=0;i=1) { for(j=incr;j= 0 && k < arr[i]; i = i-incr) arr[i+incr]=arr[i]; arr[i+incr]=k; } printf("Increment=%d ",incr); for (i = 0; i < n; i++) printf("%d ", arr[i]); printf(" "); incr=incr-2; /*Decrease the increment*/ }/*End of while*/ printf("Sorted list is : "); for (i = 0; i < n; i++) printf("%d ", arr[i]); printf(" "); }/*End of main()*/ redix sort /*Program of sorting using radix sort*/ # include # include struct node { int info ; struct node *link; }*start=NULL;
  • 7. main() { struct node *tmp,*q; int i,n,item; printf("Enter the number of elements in the list : "); scanf("%d", &n); for(i=0;iinfo=item; tmp->link=NULL; if(start==NULL) /* Inserting first element */ start=tmp; else { q=start; while(q->link!=NULL) q=q->link; q->link=tmp; } }/*End of for*/ printf("Unsorted list is : "); display(); radix_sort(); printf("Sorted list is : "); display (); }/*End of main()*/ display() { struct node *p=start; while( p !=NULL) { printf("%d ", p->info); p= p->link;
  • 8. } printf(" "); }/*End of display()*/ radix_sort() { int i,k,dig,maxdig,mindig,least_sig,most_sig; struct node *p, *rear[10], *front[10]; least_sig=1; most_sig=large_dig(start); for(k = least_sig; k <= most_sig ; k++) { printf("PASS %d : Examining %dth digit from right ",k,k); for(i = 0 ; i <= 9 ; i++) { rear[i] = NULL; front[i] = NULL ; } maxdig=0; mindig=9; p = start ; while( p != NULL) { /*Find kth digit in the number*/ dig = digit(p->info, k); if(dig>maxdig) maxdig=dig; if(diglink = p ; rear[dig] = p ; p=p->link;/*Go to next number in the list*/ }/*End while */ /* maxdig and mindig are the maximum amd minimum digits of the kth digits of all the numbers*/ printf("mindig=%d maxdig=%d ",mindig,maxdig);
  • 9. /*Join all the queues to form the new linked list*/ start=front[mindig]; for(i=mindig;ilink=front[i+1]; else rear[i+1]=rear[i]; } rear[maxdig]->link=NULL; printf("New list : "); display(); }/* End for */ }/*End of radix_sort*/ /* This function finds number of digits in the largest element of the list */ int large_dig() { struct node *p=start ; int large = 0,ndig = 0 ; while(p != NULL) { if(p ->info > large) large = p->info; p = p->link ; } printf("Largest Element is %d , ",large); while(large != 0) { ndig++; large = large/10 ; } printf("Number of digits in it are %d ",ndig); return(ndig); } /*End of large_dig()*/
  • 10. /*This function returns kth digit of a number*/ int digit(int number, int k) { int digit, i ; for(i = 1 ; i <=k ; i++) { digit = number % 10 ; number = number /10 ; } return(digit); }/*End of digit()*/