SlideShare a Scribd company logo
1 of 14
//...........HEAPSORT............................

#include<stdio.h>
#include<conio.h>
#define MAXSIZE 5
#define MAX 15
void main()
{
       int a[MAX],n,i,s,f,item,value;
       clrscr();
       printf("Enter the number of elementsn");
       scanf("%d",&n);
       printf("Enter %d elements one by onen",n);
       for(i=0;i<n;i++)
       {
               scanf("%d",&a[i]);
       }
       for(i=1;i<n;i++)
       {
               item=a[i];
               s=i;
               f=(s-1)/2;
               while(s>0 && a[f]<item)
               {
                       a[s]=a[f];
                       s=f;
                       f=(s-1)/2;
               }
               a[s]=item;
       }
       for(i=n-1;i>0;i--)
       {
               value=a[i];
               a[i]=a[0];
               f=0;
               if(i==1)
               s=-1;
       else
               s=1;
               if(i>2 && a[2]>a[1])
               s=2;
               while(s>=0 && value<a[s])
               {
                       a[f]=a[s];
                       f=s;
s=2*f+1;
                        if(s+1<=i-1 &&(a[s]<a[s+1]))
                        s=s+1;
                        if(s>i-1)
                        s=-1;
                }
                a[f]=value;
        }
        printf("nThe sorted list is n");
        for(i=0;i<n;i++)
        {
                printf("%dn",a[i]);
        }
getch();
}


output:->
Enter the number of elements
5
Enter 5 elements one by one
20
10
40
50
61

The sorted list is
10
20
40
50
61
//quick sort……………………………
#include<stdio.h>
#include<conio.h>
int lower[20],upper[20],top=-1;
int a[20],n,beg,end,loc;
void quick();
void main()
{
int i;
clrscr();
printf("How many elementsn");
scanf("%d",&n);
printf("Elements are n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
if(n>1)
{
top=top+1;
lower[0]=0;
upper[0]=n-1;
}
while(top!=-1)
{
beg=lower[top];
end=upper[top];
top=top-1;
quick();
if(beg<loc-1)
{
top=top+1;
lower[top]=beg;
upper[top]=loc-1;
}
if(loc+1<end)
{
top=top+1;
lower[top]=loc+1;
upper[top]=end;
}
}
printf("Sorted listn");
for(i=0;i<n;i++)
printf("t %dn",a[i]);
getch();
}
void quick()
{
int left,right,temp;
right1:left=beg;
right=end;
loc=beg;
while((a[loc]<=a[right])&&(loc!=right))
right=right-1;
if(loc==right)
return;
if(a[loc]>a[right])
{
temp=a[loc];
a[loc]=a[right];
a[right]=temp;
loc=right;
goto left1;
}
left1:while((a[left]<=a[loc])&&(left!=loc))
left=left+1;
if(loc==left)
return;
if(a[left]>a[loc])
{
temp=a[loc];
a[loc]=a[left];
a[left]=temp;
loc=left;
goto right1;
}
}


output:
How many elements
8
Elements are
67
45
33
11
12
43
56
78
Sorted list
     11
     12
     33
     43
     45
     56
     67
     78
//     INSERTION SORT....................
#include<stdio.h>
#include<conio.h>
void main()
{
       int a[100],n,k,i,j,temp;
       printf("How many elements : ");
       scanf("%d",&n);
       printf("Enter the elements of array : n");
       for(i=0;i<=n-1;i++)
       {
               scanf("%d",&a[i]);
       }
       for(k=1;k<n;k++)
       {
               temp=a[k];
               j=k-1;
               while((temp<a[i])&&(j>=0))
               {
                       a[j+1]=a[j];
                       j=j-1;
               }
               a[j+1]=temp;
       }
       printf("Enter element after sorting:n");
       for(i=0;i<n;i++)
       {
               printf("%dn",a[i]);
       }
}

output:->
How many elements : 5
Enter the elements of array :
2
4
3
5
1
Enter element after sorting:
1
2
3
4
5
//     BUBBLE SORT..........
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int main()
{
       int *x,n,i,j,key,found,temp;
       clrscr();
       printf("nt Enter no. of elements: ");
       scanf("%d",&n);
       printf("tAllocating Memory");
       x=(int *)malloc(n*sizeof(int));
       printf("tReading of data n");
       for(i=1;i<=n;++i)
               scanf("%d",x+i);
       for(i=1;i<=n;++i)
       {
               for(j=1;j<=n-i;++j)
               {
                        if(*(x+j)>*(x+j+1))
                        {
                                temp=*(x+j);
                                *(x+j)=*(x+j+1);
                                *(x+j+1)=temp;
                        }

               }
       }
       printf("*******Sorted Array*******n");
       for(i=1;i<=n;++i)
       {
       printf("n%d",*(x+i));
       }
       getch();
}

OUTPUT:->

     Enter no. of elements: 5
     Allocating Memory       Reading of data
12
45
67
34
52
*******Sorted Array*******

12
34
45
52
67
//     SELECTION SORT..................
#include<stdio.h>
#include<conio.h>

int *mi(int *a,int n)
{
       int i, *p=a;
       for(i=1;i<n;i++)
        if(*p<*(a+i))
        p=a+i;
        return(p);
}
void swap(int *a, int *b)
{
       int t=*a;
       *a=*b;
       *b=t;
}
void selectionsort(int *a, int n)
{
       int i;
       for(i=0;i<n-1;i++)
       {
       swap(a+i,mi(a+i,n-i));
       }
}
int main()
{
       int *x,n,i;
       clrscr();
       printf("Enter the number of elements: n");
       scanf("%d",&n);
       printf("{Allocating memory} n");
       x=(int *) malloc(n*sizeof(int));
       printf("Reading the data: n");
       for(i=0;i<n;i++)
       {
                scanf("%d",x+i);
       }
       selectionsort(x,n);
       printf("*******Sorted Array******* n");
       for(i=0;i<n;i++)
       printf("%dn",*(x+i));
       free(x);
       return 0;
}
output:->
Enter the number of elements:
5
{Allocating memory}
Reading the data:
2
5
4
3
1
*******Sorted Array*******
5
4
3
2
1
//MERGED SORT.......................


#include<stdio.h>
#include<conio.h>
void merge(int *a,int n,int *b,int m)
{
int i,j,k,*c;
c=(int *)malloc((m+n)*sizeof(int));
i=0;
j=0;
k=0;
while(i<n&&j<m)
c[k++]=(a[i]<b[j])?a[i++]:b[j++];
while(i<n)
c[k++]=a[i++];
while(j<m)
c[k++]=b[j++];
for(i=0;i<k;i++)
a[i]=c[i];
free(c);
}
void mergesort(int *arr,int n)
{
int mid;
if((n==1))return;
mid=n/2;
printf("n%d",mid);
mergesort(arr,mid);
mergesort(arr+mid,n-mid);
merge(arr,mid,arr+mid,n-mid);
}
void main()
{
int *x,i,n;
clrscr();
printf("Enter elements:");
scanf("%d",&n);
printf("Allocate memory.");
x=(int*)malloc(n*sizeof(int));
printf("Reading the data.");
for(i=0;i<n;i++)
scanf("%d",x+i);
mergesort(x,n);
printf("nElements after sorting");
for(i=0;i<n;i++)
printf("n%d",*(x+i));
free(x);
getch();
}




output:



Enter elements:5
Allocate memory.Reading the data.12
43
11
56
76

2
1
1
1
Elements after sorting
11
12
43
56
76
Sorting programs
Sorting programs

More Related Content

What's hot (20)

programs
programsprograms
programs
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
Ada file
Ada fileAda file
Ada file
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
week-21x
week-21xweek-21x
week-21x
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
Basic program in java
Basic program in java Basic program in java
Basic program in java
 
Cquestions
Cquestions Cquestions
Cquestions
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 

Viewers also liked

How to use Social Media for Educational Organizations?
How to use Social Media for Educational Organizations?How to use Social Media for Educational Organizations?
How to use Social Media for Educational Organizations?Deva Singh
 
ds and algorithm session
ds and algorithm sessionds and algorithm session
ds and algorithm sessionVarun Garg
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchartRabin BK
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1luhkahreth
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 

Viewers also liked (8)

Excel07 l1 ch1
Excel07 l1 ch1Excel07 l1 ch1
Excel07 l1 ch1
 
How to use Social Media for Educational Organizations?
How to use Social Media for Educational Organizations?How to use Social Media for Educational Organizations?
How to use Social Media for Educational Organizations?
 
ds and algorithm session
ds and algorithm sessionds and algorithm session
ds and algorithm session
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 

Similar to Sorting programs

Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)Ankit Gupta
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207Syed Tanveer
 
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
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
(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
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfapexelectronices01
 

Similar to Sorting programs (20)

C programs
C programsC programs
C programs
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Pnno
PnnoPnno
Pnno
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
week-20x
week-20xweek-20x
week-20x
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Vcs16
Vcs16Vcs16
Vcs16
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
(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++
 
Vcs29
Vcs29Vcs29
Vcs29
 
array.ppt
array.pptarray.ppt
array.ppt
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
Lab Question
Lab QuestionLab Question
Lab Question
 

Recently uploaded

Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...pujan9679
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Availablepr788182
 
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...lizamodels9
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptxnandhinijagan9867
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...ssuserf63bd7
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistanvineshkumarsajnani12
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 MonthsIndeedSEO
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...pr788182
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTSkajalroy875762
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfwill854175
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGpr788182
 
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book nowKOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...meghakumariji156
 
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAIGetting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAITim Wilson
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book nowkapoorjyoti4444
 

Recently uploaded (20)

Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
 
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableBerhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Berhampur Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
Horngren’s Cost Accounting A Managerial Emphasis, Canadian 9th edition soluti...
 
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in PakistanChallenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
Challenges and Opportunities: A Qualitative Study on Tax Compliance in Pakistan
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur 70918*19311 CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
Bangalore Call Girl Just Call♥️ 8084732287 ♥️Top Class Call Girl Service Avai...
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book nowKOTA 💋 Call Girl 9827461493 Call Girls in  Escort service book now
KOTA 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
 
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAIGetting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 

Sorting programs

  • 1. //...........HEAPSORT............................ #include<stdio.h> #include<conio.h> #define MAXSIZE 5 #define MAX 15 void main() { int a[MAX],n,i,s,f,item,value; clrscr(); printf("Enter the number of elementsn"); scanf("%d",&n); printf("Enter %d elements one by onen",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=1;i<n;i++) { item=a[i]; s=i; f=(s-1)/2; while(s>0 && a[f]<item) { a[s]=a[f]; s=f; f=(s-1)/2; } a[s]=item; } for(i=n-1;i>0;i--) { value=a[i]; a[i]=a[0]; f=0; if(i==1) s=-1; else s=1; if(i>2 && a[2]>a[1]) s=2; while(s>=0 && value<a[s]) { a[f]=a[s]; f=s;
  • 2. s=2*f+1; if(s+1<=i-1 &&(a[s]<a[s+1])) s=s+1; if(s>i-1) s=-1; } a[f]=value; } printf("nThe sorted list is n"); for(i=0;i<n;i++) { printf("%dn",a[i]); } getch(); } output:-> Enter the number of elements 5 Enter 5 elements one by one 20 10 40 50 61 The sorted list is 10 20 40 50 61
  • 3. //quick sort…………………………… #include<stdio.h> #include<conio.h> int lower[20],upper[20],top=-1; int a[20],n,beg,end,loc; void quick(); void main() { int i; clrscr(); printf("How many elementsn"); scanf("%d",&n); printf("Elements are n"); for(i=0;i<n;i++) scanf("%d",&a[i]); if(n>1) { top=top+1; lower[0]=0; upper[0]=n-1; } while(top!=-1) { beg=lower[top]; end=upper[top]; top=top-1; quick(); if(beg<loc-1) { top=top+1; lower[top]=beg; upper[top]=loc-1; } if(loc+1<end) { top=top+1; lower[top]=loc+1; upper[top]=end; } } printf("Sorted listn"); for(i=0;i<n;i++) printf("t %dn",a[i]); getch(); }
  • 4. void quick() { int left,right,temp; right1:left=beg; right=end; loc=beg; while((a[loc]<=a[right])&&(loc!=right)) right=right-1; if(loc==right) return; if(a[loc]>a[right]) { temp=a[loc]; a[loc]=a[right]; a[right]=temp; loc=right; goto left1; } left1:while((a[left]<=a[loc])&&(left!=loc)) left=left+1; if(loc==left) return; if(a[left]>a[loc]) { temp=a[loc]; a[loc]=a[left]; a[left]=temp; loc=left; goto right1; } } output: How many elements 8 Elements are 67 45 33 11 12 43 56
  • 5. 78 Sorted list 11 12 33 43 45 56 67 78
  • 6. // INSERTION SORT.................... #include<stdio.h> #include<conio.h> void main() { int a[100],n,k,i,j,temp; printf("How many elements : "); scanf("%d",&n); printf("Enter the elements of array : n"); for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); } for(k=1;k<n;k++) { temp=a[k]; j=k-1; while((temp<a[i])&&(j>=0)) { a[j+1]=a[j]; j=j-1; } a[j+1]=temp; } printf("Enter element after sorting:n"); for(i=0;i<n;i++) { printf("%dn",a[i]); } } output:-> How many elements : 5 Enter the elements of array : 2 4 3 5 1 Enter element after sorting: 1 2 3 4 5
  • 7. // BUBBLE SORT.......... #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *x,n,i,j,key,found,temp; clrscr(); printf("nt Enter no. of elements: "); scanf("%d",&n); printf("tAllocating Memory"); x=(int *)malloc(n*sizeof(int)); printf("tReading of data n"); for(i=1;i<=n;++i) scanf("%d",x+i); for(i=1;i<=n;++i) { for(j=1;j<=n-i;++j) { if(*(x+j)>*(x+j+1)) { temp=*(x+j); *(x+j)=*(x+j+1); *(x+j+1)=temp; } } } printf("*******Sorted Array*******n"); for(i=1;i<=n;++i) { printf("n%d",*(x+i)); } getch(); } OUTPUT:-> Enter no. of elements: 5 Allocating Memory Reading of data 12 45 67 34
  • 9. // SELECTION SORT.................. #include<stdio.h> #include<conio.h> int *mi(int *a,int n) { int i, *p=a; for(i=1;i<n;i++) if(*p<*(a+i)) p=a+i; return(p); } void swap(int *a, int *b) { int t=*a; *a=*b; *b=t; } void selectionsort(int *a, int n) { int i; for(i=0;i<n-1;i++) { swap(a+i,mi(a+i,n-i)); } } int main() { int *x,n,i; clrscr(); printf("Enter the number of elements: n"); scanf("%d",&n); printf("{Allocating memory} n"); x=(int *) malloc(n*sizeof(int)); printf("Reading the data: n"); for(i=0;i<n;i++) { scanf("%d",x+i); } selectionsort(x,n); printf("*******Sorted Array******* n"); for(i=0;i<n;i++) printf("%dn",*(x+i)); free(x); return 0; }
  • 10. output:-> Enter the number of elements: 5 {Allocating memory} Reading the data: 2 5 4 3 1 *******Sorted Array******* 5 4 3 2 1
  • 11. //MERGED SORT....................... #include<stdio.h> #include<conio.h> void merge(int *a,int n,int *b,int m) { int i,j,k,*c; c=(int *)malloc((m+n)*sizeof(int)); i=0; j=0; k=0; while(i<n&&j<m) c[k++]=(a[i]<b[j])?a[i++]:b[j++]; while(i<n) c[k++]=a[i++]; while(j<m) c[k++]=b[j++]; for(i=0;i<k;i++) a[i]=c[i]; free(c); } void mergesort(int *arr,int n) { int mid; if((n==1))return; mid=n/2; printf("n%d",mid); mergesort(arr,mid); mergesort(arr+mid,n-mid); merge(arr,mid,arr+mid,n-mid); } void main() { int *x,i,n; clrscr(); printf("Enter elements:"); scanf("%d",&n); printf("Allocate memory."); x=(int*)malloc(n*sizeof(int)); printf("Reading the data."); for(i=0;i<n;i++) scanf("%d",x+i); mergesort(x,n); printf("nElements after sorting");
  • 12. for(i=0;i<n;i++) printf("n%d",*(x+i)); free(x); getch(); } output: Enter elements:5 Allocate memory.Reading the data.12 43 11 56 76 2 1 1 1 Elements after sorting 11 12 43 56 76