Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * insertion Sort Algorithim
- *
- */
- #include <iostream>
- using namespace std;
- void insertionSort();
- int const n = 5;
- int A[n];
- void main() {
- for (int i = 0; i < n; i++) {
- cin >> A[i];
- }
- insertionSort();
- for (int i = 0; i < n; i++) {
- cout << A[i] << "\t";
- }
- cout << endl;
- system("pause");
- }
- void insertionSort() {
- for (int j = 1; j < n; j++) {
- int temp = A[j];
- int i;
- for (i = j - 1; (i >= 0) && (temp > A[i]); i--) {
- A[i + 1] = A[i];//shift
- /*
- for (int i = 0; i < n; i++) {
- cout << A[i] << "\t";
- cout << endl;
- }
- */
- }
- A[i + 1] = temp; // insertion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement