SlideShare a Scribd company logo
//Program to sort array using insertion sort
#include<iostream.h>
#include<limits.h>
void inssort(int[], int);
void main()
{
int ar[50], item, n, index;
cout<<" How many elements do you want to create an array with? (max 50) ";
cin>>n;
cout<<"n Enter the array elements..";
for (int i=1; i<=n; i++)
cin>>ar[i];
inssort(ar, n);
cout<<"n The sorted array is as shown below";
for (int i=1; i<=n; i++)
cout<<ar[i]<<" n";
}
void inssort( int ar[], int size)
{
int tmp, j;
ar[0]=IMI_MIN;
for (int i=1; i<= size; i++)
{
tmp=ar[i];
j=i-1;
while tmp<ar[j];
j--;
}
ar[j+1]=tmp;
cout<< "array after pass "<< i <<" is ";
for (int i=1; i<= size; i++)
cout<< ar[k]<<" ";
cout<<endl;
}
}
Ad

Recommended

Document
Document
AjitRaj12
 
PROGRAM FOR INSERTION SORTING IN ARRAY
PROGRAM FOR INSERTION SORTING IN ARRAY
daemian2
 
Sol10
Sol10
University Of Lahore
 
Data Visualization — Le funzionalità matematiche di Sage per la visualizzazio...
Data Visualization — Le funzionalità matematiche di Sage per la visualizzazio...
Andrea Lazzarotto
 
Code
Code
Lay Chan Dara Raksmey
 
Abebe1
Abebe1
abemekie
 
C++ question 6 || solution of Programming Problem
C++ question 6 || solution of Programming Problem
Topics MixeR
 
Problemas de Arreglos en c++
Problemas de Arreglos en c++
Manfred Ariel Martinez Bastos
 
cosc 281 hw2
cosc 281 hw2
Brian Goggins
 
Insertion sort
Insertion sort
Hitesh Kumar
 
Ruby haskell extension
Ruby haskell extension
Toshiyuki Terashita
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Ooprc3c
Ooprc3c
Ankit Dubey
 
1
1
swetha gokavarapu
 
A Shiny Example-- R
A Shiny Example-- R
Dr. Volkan OBAN
 
メディアアートにおけるプログラミング言語Rubyの役割
メディアアートにおけるプログラミング言語Rubyの役割
Koichiro Eto
 
Ps installedsoftware
Ps installedsoftware
Elihu El, ITIL, SCRUM Master
 
Code sources des fonctions table cp
Code sources des fonctions table cp
idhem110
 
Go Containers
Go Containers
jgrahamc
 
Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.
university of Gujrat, pakistan
 
Om (Cont.)
Om (Cont.)
Taku Fukushima
 
Oprerator overloading
Oprerator overloading
Parthipan Parthi
 
Vcs23
Vcs23
Malikireddy Bramhananda Reddy
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5
Knoldus Inc.
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
Santiago Sarmiento
 
Ee
Ee
Syeda Muskaan
 
Programa expresiones regulares
Programa expresiones regulares
Anel Sosa
 
contoh Program queue
contoh Program queue
Bina Sarana Informatika
 
Concatenation of two strings using class in c++
Concatenation of two strings using class in c++
Swarup Boro
 
Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
Swarup Boro
 

More Related Content

What's hot (20)

cosc 281 hw2
cosc 281 hw2
Brian Goggins
 
Insertion sort
Insertion sort
Hitesh Kumar
 
Ruby haskell extension
Ruby haskell extension
Toshiyuki Terashita
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Ooprc3c
Ooprc3c
Ankit Dubey
 
1
1
swetha gokavarapu
 
A Shiny Example-- R
A Shiny Example-- R
Dr. Volkan OBAN
 
メディアアートにおけるプログラミング言語Rubyの役割
メディアアートにおけるプログラミング言語Rubyの役割
Koichiro Eto
 
Ps installedsoftware
Ps installedsoftware
Elihu El, ITIL, SCRUM Master
 
Code sources des fonctions table cp
Code sources des fonctions table cp
idhem110
 
Go Containers
Go Containers
jgrahamc
 
Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.
university of Gujrat, pakistan
 
Om (Cont.)
Om (Cont.)
Taku Fukushima
 
Oprerator overloading
Oprerator overloading
Parthipan Parthi
 
Vcs23
Vcs23
Malikireddy Bramhananda Reddy
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5
Knoldus Inc.
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
Santiago Sarmiento
 
Ee
Ee
Syeda Muskaan
 
Programa expresiones regulares
Programa expresiones regulares
Anel Sosa
 
contoh Program queue
contoh Program queue
Bina Sarana Informatika
 

More from Swarup Boro (20)

Concatenation of two strings using class in c++
Concatenation of two strings using class in c++
Swarup Boro
 
Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
Swarup Boro
 
Array using recursion
Array using recursion
Swarup Boro
 
Binary addition using class concept in c++
Binary addition using class concept in c++
Swarup Boro
 
Study of Diffusion of solids in Liquids
Study of Diffusion of solids in Liquids
Swarup Boro
 
Program using function overloading
Program using function overloading
Swarup Boro
 
Program to find the avg of two numbers
Program to find the avg of two numbers
Swarup Boro
 
Program to find factorial of a number
Program to find factorial of a number
Swarup Boro
 
Canteen management program
Canteen management program
Swarup Boro
 
C++ program using class
C++ program using class
Swarup Boro
 
Railway reservation
Railway reservation
Swarup Boro
 
Boolean
Boolean
Swarup Boro
 
Classes
Classes
Swarup Boro
 
Constructor & destructor
Constructor & destructor
Swarup Boro
 
Arrays and library functions
Arrays and library functions
Swarup Boro
 
Pointers
Pointers
Swarup Boro
 
Queue
Queue
Swarup Boro
 
Structures in c++
Structures in c++
Swarup Boro
 
Stack
Stack
Swarup Boro
 
Functions
Functions
Swarup Boro
 
Concatenation of two strings using class in c++
Concatenation of two strings using class in c++
Swarup Boro
 
Program: Inheritance in Class - to find topper out of 10 students
Program: Inheritance in Class - to find topper out of 10 students
Swarup Boro
 
Array using recursion
Array using recursion
Swarup Boro
 
Binary addition using class concept in c++
Binary addition using class concept in c++
Swarup Boro
 
Study of Diffusion of solids in Liquids
Study of Diffusion of solids in Liquids
Swarup Boro
 
Program using function overloading
Program using function overloading
Swarup Boro
 
Program to find the avg of two numbers
Program to find the avg of two numbers
Swarup Boro
 
Program to find factorial of a number
Program to find factorial of a number
Swarup Boro
 
Canteen management program
Canteen management program
Swarup Boro
 
C++ program using class
C++ program using class
Swarup Boro
 
Railway reservation
Railway reservation
Swarup Boro
 
Constructor & destructor
Constructor & destructor
Swarup Boro
 
Arrays and library functions
Arrays and library functions
Swarup Boro
 
Structures in c++
Structures in c++
Swarup Boro
 
Ad

Recently uploaded (20)

PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Chalukyas of Gujrat, Solanki Dynasty NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
PEST OF WHEAT SORGHUM BAJRA and MINOR MILLETS.pptx
Arshad Shaikh
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Ad

Program to sort array using insertion sort

  • 1. //Program to sort array using insertion sort #include<iostream.h> #include<limits.h> void inssort(int[], int); void main() { int ar[50], item, n, index; cout<<" How many elements do you want to create an array with? (max 50) "; cin>>n; cout<<"n Enter the array elements.."; for (int i=1; i<=n; i++) cin>>ar[i]; inssort(ar, n); cout<<"n The sorted array is as shown below"; for (int i=1; i<=n; i++) cout<<ar[i]<<" n"; } void inssort( int ar[], int size) { int tmp, j; ar[0]=IMI_MIN; for (int i=1; i<= size; i++) { tmp=ar[i]; j=i-1; while tmp<ar[j]; j--; } ar[j+1]=tmp; cout<< "array after pass "<< i <<" is "; for (int i=1; i<= size; i++) cout<< ar[k]<<" "; cout<<endl; } }