UNIVERSITY OF THE PUNJAB
Fourth Semester 2017
Examination: B.S. 4 Years Programme
Paper: Data Structure and Algorithm
Course Code: IT-207 / IT-22408
Short Questions
d) Write down the code for Insertion Sort.
void InsertionSort (int A[],int size);
void insertionSort(int A[], int n)
{
int i, key, j;
for (i = 1; i < n; i++)
{
key = A[i];
j = i-1;
while (j >= 0 && A[j] > key)
{
A[j+1] = A[j];
j = j-1;
}
A[j+1] = key;
}
}
Let me know in the comment section if you have any question.
Previous Post:
For the following given data below draw the Max-Heap Data is: 15, 3, 6, 18, 5, 9, 11, 20, 17, 7, 2, 3, 14 | PU | Past Paper 2017
Comments
Post a Comment