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.2K
Intelligence Online

One of the most important developments in the history of man is that of paper and books. E...

1675638330.png
Adil Khan
10 months ago
On-Demand Service Application: Muavin

Through on demand-service application you will be able to get anything, anywhere, anytime...

1675638330.png
Adil Khan
10 months ago
SMART WHEELCHAIR RAILING

In Pakistan, around three million people are disable. Advancements in technology made disa...

1675638330.png
Adil Khan
10 months ago
Smart and Secure Campus

Smart &amp; Secure Campus is a multi-purpose desktop application. It is designed on the la...

1675638330.png
Adil Khan
10 months ago
quelink isp management system15171

There are several ISPs (Internet Service Providerss) functioning today; they get their CIR...

1675638330.png
Adil Khan
10 months ago