Professional Documents
Culture Documents
1
2
3
4
5
6
7
8
Instr:
Subm. Date:
Yabello, Ethiopia
TABLE OF CONTENTS
INTRODUCTION
1.INSERTION SORT
Algorithm:
Step 1 − Start
Step 2 − Initialize the value of gap size. Example: h
Step 3 − Divide the list into smaller sub-part. Each must have equal
intervals to h
Step 4 − Sort these sub-lists using insertion sort
Step 5 – Repeat this step 2 until the list is sorted.
Step 6 – Print a sorted list.
Step 7 – Stop.
Pseudocode :
PROCEDURE SHELL_SORT(ARRAY, N)
WHILE GAP < LENGTH(ARRAY) /3 :
GAP = ( INTERVAL * 3 ) + 1
END WHILE LOOP
WHILE GAP > 0 :
FOR (OUTER = GAP; OUTER < LENGTH(ARRAY); OUTER+
+):
INSERTION_VALUE = ARRAY[OUTER]
INNER = OUTER;
WHILE INNER > GAP-1 AND ARRAY[INNER – GAP] >=
INSERTION_VALUE:
ARRAY[INNER] = ARRAY[INNER – GAP]
INNER = INNER – GAP
END WHILE LOOP
ARRAY[INNER] = INSERTION_VALUE
END FOR LOOP
GAP = (GAP -1) /3;
END WHILE LOOP
END SHELL_SORT
#include<iostream>
using namespace std;
void swap(int arr[] , int pos1, int pos2){
int temp;
temp = arr[pos1];
arr[pos1] = arr[pos2];
arr[pos2] = temp;
}
int main()
{
int n ;
cout << " enter the size of array\n" ;
cin>>n;
cout<<"enter these array\n";
int arr[n];
for( int i = 0 ; i < n; i++){
cin>> arr[i];
}
quickSort(arr, 0 , n-1);
cout<<"The sorted array is: ";
for( int i = 0 ; i < n; i++){
cout<< arr[i]<<"\t";
}
2.QUICK SORT
int main()
{
int n ;
cout << " enter the size of array";
cin>>n;
int arr[n];
for( int i = 0 ; i < n; i++){
cin>> arr[i];
}
quickSort(arr, 0 , n-1);
cout<<"The sorted array is: ";
for( int i = 0 ; i < n; i++){
cout<< arr[i]<<"\t";
}
SUMMARY
References