Adil Khan 7 years ago
AdiKhanOfficial #Data Structures

C++ Program for Insertion Sort

#include <iostream>

using namespace std;

void insertionSort(int *arr,int n){

  int i, temp, j;
  for (i = 1; i < n; i++)
  {
    temp = arr[i];
    j = i-1;

    while (j >= 0 && arr[j] > temp)
    {
      arr[j+1] = arr[j];
      j = j-1;
    }
    arr[j+1] = temp;
  }

}

int main()
{
  int arr[5],counter=0;
  for(int i=0;i<5;i++){
    cout<<"Enter a Number : ";
    cin>>arr[i];
    counter++;
    insertionSort(arr,counter);

    for(int j=0;j<counter;j++){
      cout<<arr[j]<<" ";
    }
    cout<<endl;



  }
  return 0;
}


0
1.3K
Ai based Tomato leaf Disease Prediction and Cure

Agriculture is the major source of food for the huge population in Pakistan. Its contribut...

1675638330.png
Adil Khan
1 year ago
Explore World

In some country?s tourism contributes a major part in country?s economy. Countries like Fr...

1675638330.png
Adil Khan
1 year ago
Skin Disease Detection

e>Our project is about skin disease detection, in which we have worked on 4 major diseases...

1675638330.png
Adil Khan
1 year ago
Web Based Research Paper Recommender System Using deep learning

Our project take input of title, keywords and abstract as input and then we apply algorith...

1675638330.png
Adil Khan
1 year ago
IOT based intelligent Surveillance System

Security Monitoring plays an important role in coordinating the planning, most criminal ac...

1675638330.png
Adil Khan
1 year ago