SlideShare a Scribd company logo
/* 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

DOCX
DAA Lab Work.docx
PDF
For this homework, you will write a program to create and manipulate.pdf
DOCX
ADA FILE
DOCX
Data Structures Using C Practical File
PDF
DSA.pdf
PDF
DSC program.pdf
DAA Lab Work.docx
For this homework, you will write a program to create and manipulate.pdf
ADA FILE
Data Structures Using C Practical File
DSA.pdf
DSC program.pdf

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

DOC
PDF
Program In C You are required to write an interactive C program that.pdf
DOCX
DAA Lab File C Programs
PPTX
LectureSlidData_sturcture_algorithm_v2.pptx
PPTX
Linkedlist with each and every step Single. doubly
DOC
Daapracticals 111105084852-phpapp02
DOC
Sorting programs
PPTX
Address calculation-sort
PPTX
PPT.pptx Searching and Sorting Techniques
PPT
array
PDF
C++ Searching & Sorting5. Sort the following list using the select.pdf
PPTX
Arrays
DOCX
DOC
Basic c programs updated on 31.8.2020
DOCX
Write a complete C programme to implement the following sorting algor.docx
PDF
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
DOCX
-- Reminder that your file name is incredibly important- Please do not.docx
Program In C You are required to write an interactive C program that.pdf
DAA Lab File C Programs
LectureSlidData_sturcture_algorithm_v2.pptx
Linkedlist with each and every step Single. doubly
Daapracticals 111105084852-phpapp02
Sorting programs
Address calculation-sort
PPT.pptx Searching and Sorting Techniques
array
C++ Searching & Sorting5. Sort the following list using the select.pdf
Arrays
Basic c programs updated on 31.8.2020
Write a complete C programme to implement the following sorting algor.docx
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
-- Reminder that your file name is incredibly important- Please do not.docx
Ad

More from anujmkt (20)

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

Recently uploaded (20)

PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Sports Quiz easy sports quiz sports quiz
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Cell Structure & Organelles in detailed.
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Institutional Correction lecture only . . .
PDF
01-Introduction-to-Information-Management.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
FourierSeries-QuestionsWithAnswers(Part-A).pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
GDM (1) (1).pptx small presentation for students
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
RMMM.pdf make it easy to upload and study
Pharmacology of Heart Failure /Pharmacotherapy of CHF
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
Sports Quiz easy sports quiz sports quiz
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPH.pptx obstetrics and gynecology in nursing
Cell Structure & Organelles in detailed.
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
Supply Chain Operations Speaking Notes -ICLT Program
Institutional Correction lecture only . . .
01-Introduction-to-Information-Management.pdf
Microbial disease of the cardiovascular and lymphatic systems
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

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()*/