forked from WaderManasi/Knowing-DataStructures-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
452227b
commit 543dcfa
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
//Name :Manasi Mohan Wader. // | ||
//Program :Shell Sort. // | ||
//Approach :Using Array. // | ||
//Language :C++ // | ||
//Functions:To perform ascending sorting of elements. // // | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include<iostream> | ||
#define MAX 30 | ||
using namespace std; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
void ShellSort(int arr[],int size) | ||
{ | ||
for(int gap=size/2;gap>=1;gap=gap/2) | ||
{ | ||
for(int j=gap;j<size;j++) | ||
{ | ||
for(int i=j-gap;i>=0;i=i-gap) | ||
{ | ||
if(arr[i]<arr[i+gap]) | ||
break; | ||
else | ||
{ | ||
int temp; | ||
temp=arr[i]; | ||
arr[i]=arr[i+gap]; | ||
arr[i+gap]=temp; | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
int main() | ||
{ | ||
int size; | ||
int arr[MAX]; | ||
cin>>size; | ||
for(int i=0;i<size;i++) | ||
{ | ||
cin>>arr[i]; | ||
} | ||
cout<<"\nInitial Array : "; | ||
for(int i=0;i<size;i++) | ||
cout<<arr[i]<<" "; | ||
ShellSort(arr,size); | ||
cout<<"\nSorted Array : "; | ||
for(int i=0;i<size;i++) | ||
cout<<arr[i]<<" "; | ||
return 0; | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
//End of code | ||
/////////////////////////////////////////////////////////////////////////////////// |