SlideShare ist ein Scribd-Unternehmen logo
1 von 5
/* Write C program that implement the following sorting methods to sort a given list of integers in
ascending order:

ii) Merge sort */



#include <stdio.h>

#include <stdlib.h>



#define MAX_ARY 10



void merge_sort(int x[], int end, int start);



int main(void) {

int ary[MAX_ARY];

int j = 0;



printf("nnEnter the elements to be sorted: n");

  for(j=0;j<MAX_ARY;j++)

     scanf("%d",&ary[j]);



/* array before mergesort */

printf("Before      :");

for(j = 0; j < MAX_ARY; j++)

 printf(" %d", ary[j]);



printf("n");
merge_sort(ary, 0, MAX_ARY - 1);



/* array after mergesort */

printf("After Merge Sort :");

for(j = 0; j < MAX_ARY; j++)

    printf(" %d", ary[j]);



printf("n");

getch();

}



/* Method to implement Merge Sort*/

void merge_sort(int x[], int end, int start) {

int j = 0;

const int size = start - end + 1;

int mid = 0;

int mrg1 = 0;

int mrg2 = 0;

int executing[MAX_ARY];



if(end == start)

    return;
mid = (end + start) / 2;



merge_sort(x, end, mid);

merge_sort(x, mid + 1, start);



for(j = 0; j < size; j++)

    executing[j] = x[end + j];



mrg1 = 0;

mrg2 = mid - end + 1;



for(j = 0; j < size; j++) {

    if(mrg2 <= start - end)

    if(mrg1 <= mid - end)

     if(executing[mrg1] > executing[mrg2])

     x[j + end] = executing[mrg2++];

     else

     x[j + end] = executing[mrg1++];

    else

     x[j + end] = executing[mrg2++];

    else

    x[j + end] = executing[mrg1++];

}

}
/* Write C program that implement the following sorting methods

to sort a given list of integers in ascending order: i) Insertion sort */



#include<stdio.h>

#include<conio.h>



void inst_sort(int []);



void main()

{

    int num[5],count;

    clrscr();

    printf("nEnter the Five Elements to sort:n");



    for (count=0;count<5;count++)

     scanf("%d",&num[count]);

     inst_sort(num);



    printf("nnElements after sorting: n");

    for(count=0;count<5;count++)

     printf("%dn",num[count]);
getch();

}



// Function for Insertion Sorting

void inst_sort(int num[])

{

int i,j,k;

for(j=1;j<5;j++)

    {

        k=num[j];

        for(i=j-1;i>=0 && k<num[i];i--)

         num[i+1]=num[i];

         num[i+1]=k;

    }

}

Weitere ähnliche Inhalte

Was ist angesagt? (20)

C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
week-11x
week-11xweek-11x
week-11x
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
week-10x
week-10xweek-10x
week-10x
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
week-4x
week-4xweek-4x
week-4x
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 
Linear search
Linear searchLinear search
Linear search
 
SATySFiのこれからの課題たち
SATySFiのこれからの課題たちSATySFiのこれからの課題たち
SATySFiのこれからの課題たち
 
Document
DocumentDocument
Document
 
Examples sandhiya class'
Examples sandhiya class'Examples sandhiya class'
Examples sandhiya class'
 
week-6x
week-6xweek-6x
week-6x
 
C & Python Introduction
C & Python IntroductionC & Python Introduction
C & Python Introduction
 
Avl tree
Avl treeAvl tree
Avl tree
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Computer programing w
Computer programing wComputer programing w
Computer programing w
 
New microsoft word document
New microsoft word documentNew microsoft word document
New microsoft word document
 
cosc 281 hw2
cosc 281 hw2cosc 281 hw2
cosc 281 hw2
 

Andere mochten auch

腾讯大讲堂28 用户与产品的桥梁
腾讯大讲堂28 用户与产品的桥梁腾讯大讲堂28 用户与产品的桥梁
腾讯大讲堂28 用户与产品的桥梁George Ang
 
2011 03 auto.sk
2011 03 auto.sk2011 03 auto.sk
2011 03 auto.skOneClick
 
Com scorewhithertheclickeurope0309
Com scorewhithertheclickeurope0309Com scorewhithertheclickeurope0309
Com scorewhithertheclickeurope0309SHIJU VARGHESE
 
基于Eucalyptus的教育知识服务体系模型研究
基于Eucalyptus的教育知识服务体系模型研究基于Eucalyptus的教育知识服务体系模型研究
基于Eucalyptus的教育知识服务体系模型研究liangxiao0315
 
Hadoop @ Sara & BiG Grid
Hadoop @ Sara & BiG GridHadoop @ Sara & BiG Grid
Hadoop @ Sara & BiG GridEvert Lammerts
 
использование свободного программного обеспечения в ВУЗах Украины
использование свободного программного обеспечения в ВУЗах Украиныиспользование свободного программного обеспечения в ВУЗах Украины
использование свободного программного обеспечения в ВУЗах УкраиныТранслируем.бел
 
腾讯大讲堂36 竞争情报入门
腾讯大讲堂36 竞争情报入门腾讯大讲堂36 竞争情报入门
腾讯大讲堂36 竞争情报入门George Ang
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Open Source Бизнес или о том как открыть 90% и остаться со штанами
Open Source Бизнес или о том как открыть 90% и остаться со штанамиOpen Source Бизнес или о том как открыть 90% и остаться со штанами
Open Source Бизнес или о том как открыть 90% и остаться со штанамиТранслируем.бел
 
Deep C Programming
Deep C ProgrammingDeep C Programming
Deep C ProgrammingWang Hao Lee
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questionsadarshynl
 

Andere mochten auch (18)

C programming part1
C programming part1C programming part1
C programming part1
 
C
CC
C
 
腾讯大讲堂28 用户与产品的桥梁
腾讯大讲堂28 用户与产品的桥梁腾讯大讲堂28 用户与产品的桥梁
腾讯大讲堂28 用户与产品的桥梁
 
2011 03 auto.sk
2011 03 auto.sk2011 03 auto.sk
2011 03 auto.sk
 
Gemius
GemiusGemius
Gemius
 
Com scorewhithertheclickeurope0309
Com scorewhithertheclickeurope0309Com scorewhithertheclickeurope0309
Com scorewhithertheclickeurope0309
 
基于Eucalyptus的教育知识服务体系模型研究
基于Eucalyptus的教育知识服务体系模型研究基于Eucalyptus的教育知识服务体系模型研究
基于Eucalyptus的教育知识服务体系模型研究
 
Hadoop @ Sara & BiG Grid
Hadoop @ Sara & BiG GridHadoop @ Sara & BiG Grid
Hadoop @ Sara & BiG Grid
 
использование свободного программного обеспечения в ВУЗах Украины
использование свободного программного обеспечения в ВУЗах Украиныиспользование свободного программного обеспечения в ВУЗах Украины
использование свободного программного обеспечения в ВУЗах Украины
 
腾讯大讲堂36 竞争情报入门
腾讯大讲堂36 竞争情报入门腾讯大讲堂36 竞争情报入门
腾讯大讲堂36 竞争情报入门
 
C++ basics
C++ basicsC++ basics
C++ basics
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Open Source Бизнес или о том как открыть 90% и остаться со штанами
Open Source Бизнес или о том как открыть 90% и остаться со штанамиOpen Source Бизнес или о том как открыть 90% и остаться со штанами
Open Source Бизнес или о том как открыть 90% и остаться со штанами
 
ch6
ch6ch6
ch6
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
Deep C Programming
Deep C ProgrammingDeep C Programming
Deep C Programming
 
C programming interview questions
C programming interview questionsC programming interview questions
C programming interview questions
 

Ähnlich wie week-21x

DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
 
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxMerge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxscroghamtressie
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solutionAzhar Javed
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
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.2020vrgokila
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming LanguageArkadeep Dey
 
Sorting programs
Sorting programsSorting programs
Sorting programsVarun Garg
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
Double linked list
Double linked listDouble linked list
Double linked listSayantan Sur
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
Write a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdfWrite a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdfarchanaemporium
 
Single linked list
Single linked listSingle linked list
Single linked listSayantan Sur
 

Ähnlich wie week-21x (20)

DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Pnno
PnnoPnno
Pnno
 
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docxMerge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
C programs
C programsC programs
C programs
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
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
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Double linked list
Double linked listDouble linked list
Double linked list
 
week-20x
week-20xweek-20x
week-20x
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Write a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdfWrite a program (any language) to randomly generate the following se.pdf
Write a program (any language) to randomly generate the following se.pdf
 
Single linked list
Single linked listSingle linked list
Single linked list
 

Mehr von KITE www.kitecolleges.com (20)

PPT (2)
PPT (2)PPT (2)
PPT (2)
 
week-1x
week-1xweek-1x
week-1x
 
ch14
ch14ch14
ch14
 
ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-16x
week-16xweek-16x
week-16x
 
week-5x
week-5xweek-5x
week-5x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-23x
week-23xweek-23x
week-23x
 
week-2x
week-2xweek-2x
week-2x
 

Kürzlich hochgeladen

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 

Kürzlich hochgeladen (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

week-21x

  • 1. /* Write C program that implement the following sorting methods to sort a given list of integers in ascending order: ii) Merge sort */ #include <stdio.h> #include <stdlib.h> #define MAX_ARY 10 void merge_sort(int x[], int end, int start); int main(void) { int ary[MAX_ARY]; int j = 0; printf("nnEnter the elements to be sorted: n"); for(j=0;j<MAX_ARY;j++) scanf("%d",&ary[j]); /* array before mergesort */ printf("Before :"); for(j = 0; j < MAX_ARY; j++) printf(" %d", ary[j]); printf("n");
  • 2. merge_sort(ary, 0, MAX_ARY - 1); /* array after mergesort */ printf("After Merge Sort :"); for(j = 0; j < MAX_ARY; j++) printf(" %d", ary[j]); printf("n"); getch(); } /* Method to implement Merge Sort*/ void merge_sort(int x[], int end, int start) { int j = 0; const int size = start - end + 1; int mid = 0; int mrg1 = 0; int mrg2 = 0; int executing[MAX_ARY]; if(end == start) return;
  • 3. mid = (end + start) / 2; merge_sort(x, end, mid); merge_sort(x, mid + 1, start); for(j = 0; j < size; j++) executing[j] = x[end + j]; mrg1 = 0; mrg2 = mid - end + 1; for(j = 0; j < size; j++) { if(mrg2 <= start - end) if(mrg1 <= mid - end) if(executing[mrg1] > executing[mrg2]) x[j + end] = executing[mrg2++]; else x[j + end] = executing[mrg1++]; else x[j + end] = executing[mrg2++]; else x[j + end] = executing[mrg1++]; } }
  • 4. /* Write C program that implement the following sorting methods to sort a given list of integers in ascending order: i) Insertion sort */ #include<stdio.h> #include<conio.h> void inst_sort(int []); void main() { int num[5],count; clrscr(); printf("nEnter the Five Elements to sort:n"); for (count=0;count<5;count++) scanf("%d",&num[count]); inst_sort(num); printf("nnElements after sorting: n"); for(count=0;count<5;count++) printf("%dn",num[count]);
  • 5. getch(); } // Function for Insertion Sorting void inst_sort(int num[]) { int i,j,k; for(j=1;j<5;j++) { k=num[j]; for(i=j-1;i>=0 && k<num[i];i--) num[i+1]=num[i]; num[i+1]=k; } }