SlideShare a Scribd company logo
...es of C++Insertion_Sort_codeInsertion_Sort_code.cpp 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Insertion_Sort_code.cpp : This file contains the 'main' function.
Program execution begins and ends there.
//
#include < iostream >
using namespace std;
void insertionSort(int arr[])
{
int key;
int j = 0;
for (int i = 1; i < 5; i++)
{
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
int main() {
int myarray[5];
cout << "Enter 5 integers in any order" << endl;
for (int i = 0; i < 5; i++)
{
cout << "myarray[" << i << "] : ";
cin >> myarray[i];
}
cout << endl << endl;
cout << "Before Sorting: " << endl;
for (int i = 0; i < 5; i++)
{
cout << "myarray[" << i << "] : " << myarray[i] << endl;
}
insertionSort(myarray);
cout << endl << endl;
cout << endl << "After Sorting: " << endl;
for (int i = 0; i < 5; i++)
{
cout << "myarray[" << i << "] : "<< myarray[i] << endl;
}
...es of C++Insertion_Sort_codeInsertion_Sort_code.cpp 2
49
50
return 0;
}

More Related Content

PPTX
UNIT 2 LOOP CONTROL.pptx
PDF
pattern-printing-in-c.pdf
PDF
Pattern printing-in-c(Jaydip Kikani)
DOCX
Programa.eje
PPTX
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
DOCX
Network lap pgms 7th semester
PDF
C++ Programming - 2nd Study
UNIT 2 LOOP CONTROL.pptx
pattern-printing-in-c.pdf
Pattern printing-in-c(Jaydip Kikani)
Programa.eje
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
Network lap pgms 7th semester
C++ Programming - 2nd Study

Similar to Insertion_Sort_Code.pdf (20)

PDF
Set 6 fundamental of programing file pagea
DOCX
Ejercicios de programacion
PDF
Stl algorithm-Basic types
PDF
Insertion Sort Code
PDF
C++ L04-Array+String
PPTX
array ppt of c programing language for exam
PDF
C programs
PDF
Python 1 liners
PPTX
Java parallel programming made simple
PPS
pointers 1
PPTX
Object Oriented Programming - Value Types & Reference Types
DOCX
Chapter 8 c solution
DOCX
PRACTICAL COMPUTING
DOCX
ماترێکس به‌ کوردی ئارام
PPTX
CP 04.pptx
PPT
PPTX
Managing console
PPT
Practical basics on c++
Set 6 fundamental of programing file pagea
Ejercicios de programacion
Stl algorithm-Basic types
Insertion Sort Code
C++ L04-Array+String
array ppt of c programing language for exam
C programs
Python 1 liners
Java parallel programming made simple
pointers 1
Object Oriented Programming - Value Types & Reference Types
Chapter 8 c solution
PRACTICAL COMPUTING
ماترێکس به‌ کوردی ئارام
CP 04.pptx
Managing console
Practical basics on c++

Recently uploaded (20)

PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPT
introduction to datamining and warehousing
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Artificial Intelligence
DOCX
573137875-Attendance-Management-System-original
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
CH1 Production IntroductoryConcepts.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
introduction to datamining and warehousing
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Artificial Intelligence
573137875-Attendance-Management-System-original
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Current and future trends in Computer Vision.pptx
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Foundation to blockchain - A guide to Blockchain Tech
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx

Insertion_Sort_Code.pdf

  • 1. ...es of C++Insertion_Sort_codeInsertion_Sort_code.cpp 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 // Insertion_Sort_code.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include < iostream > using namespace std; void insertionSort(int arr[]) { int key; int j = 0; for (int i = 1; i < 5; i++) { key = arr[i]; j = i - 1; while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } } int main() { int myarray[5]; cout << "Enter 5 integers in any order" << endl; for (int i = 0; i < 5; i++) { cout << "myarray[" << i << "] : "; cin >> myarray[i]; } cout << endl << endl; cout << "Before Sorting: " << endl; for (int i = 0; i < 5; i++) { cout << "myarray[" << i << "] : " << myarray[i] << endl; } insertionSort(myarray); cout << endl << endl; cout << endl << "After Sorting: " << endl; for (int i = 0; i < 5; i++) { cout << "myarray[" << i << "] : "<< myarray[i] << endl; }