0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

Insertion Sort

1,079

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total Views
1,079
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
78
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript

• 1. Insertion Sort CH Gowri Kumar [email_address]
• 2. Insertion Sort
• Consists of N-1 passes
• For pass P = 1 through N-1, insertion sort ensures that the elements in positions 0 through P are in the sorted order
• In pass P, the element in the position P is moved left until its correct place is found among the first P + 1 elements.
• Complexity - O(n 2 )
• 3. void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 4. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 5. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 6. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 7. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 8. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for( P = 1 ;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 9. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1 ;P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 10. 34 8 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 11. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 12. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for ( j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 13. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 14. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 15. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 16. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 17. 34 64 51 32 21 8 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 18. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 19. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 20. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 21. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1; P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 22. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 23. 8 34 51 32 21 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 24. 8 34 51 32 21 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for ( j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 25. 8 34 51 32 21 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 26. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 27. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 28. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 29. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1; P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 30. 8 34 64 51 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 31. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 32. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for ( j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 33. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 34. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 35. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 36. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 37. 8 34 64 32 21 51 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 38. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 39. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 40. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 41. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 42. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1; P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 43. 8 34 51 64 32 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 44. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 45. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for ( j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 46. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 47. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 48. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 49. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 50. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 51. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 52. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 53. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 54. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 55. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 56. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 57. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 58. 8 34 51 64 21 32 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 59. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 60. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 61. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 62. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 63. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1; P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 64. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 65. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 66. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for ( j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 67. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 68. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 69. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 70. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 71. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 72. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 73. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 74. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 75. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 76. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 77. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 78. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 79. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 80. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 81. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j-- ) A[ j] = A[j-1]; A[j] = Tmp; } }
• 82. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P; j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 83. 8 32 34 51 64 21 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 84. 8 21 32 34 51 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp ; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 85. 8 21 32 34 51 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 86. 8 21 32 34 51 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++ ) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 87. 8 21 32 34 51 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1; P<N ; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 88. 8 21 32 34 51 64 void InsertionSort(ElementType A[ ], int N) { int j, P; ElementType Tmp; for(P = 1;P<N; P++) { Tmp = A[P]; for (j = P;j>0 && A[j-1] > Tmp; j--) A[ j] = A[j-1]; A[j] = Tmp; } }
• 89. The End