Docsity

Shell Sorting and Bucket Sorting C++ Code for Data Structures Assignment in CSM 388, Lecture notes of Data Structures and Algorithms

Toggle sidebar
bg1
ASSIGNMENT
DATA STRUCTURES CSM 388
NAME: OSIE BISMARK
INDEX: 1656217
SHELL SORTING C++ CODE
void shellSort(int array[], int size) {
int gap, j, k,temp;
for(gap = size/2; gap > 0; gap = gap / 2) { //initially gap = n/2,
//decreasing by gap /2
for(j = gap; j<size; j++) {
for(k = j-gap; k >= 0; k -= gap) {
if(array[k+gap] >= array[k])
break;
else
0.\]=[-P0;']
\-*9/8 temp = array[k+gap];
array[k+gap] = array[k];
array[k] = temp;
}
}
cout <<"\n Using" << gap << " ";
gap;
printArray();
}
}
BUCKET SORTING C++ CODE
void bucketSort(int array[],int size)
{
pf2

Partial preview of the text

Download Shell Sorting and Bucket Sorting C++ Code for Data Structures Assignment in CSM 388 and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

ASSIGNMENT

DATA STRUCTURES CSM 388

NAME: OSIE BISMARK

INDEX: 1656217

SHELL SORTING C++ CODE

void shellSort(int array[], int size) { int gap, j, k,temp; for(gap = size/2; gap > 0; gap = gap / 2) { //initially gap = n/2, //decreasing by gap / for(j = gap; j<size; j++) { for(k = j-gap; k >= 0; k -= gap) { if(array[k+gap] >= array[k]) break; else 0.]=[-P0;'] -*9/8 temp = array[k+gap]; array[k+gap] = array[k]; array[k] = temp; } } cout <<"\n Using" << gap << " "; gap; printArray(); } }

BUCKET SORTING C++ CODE

void bucketSort(int array[],int size) {

vector bucket[size]; for (int i = 0; i < size; i++) { bucket[int(array[i] * size)].push_back(array[i]); } for (int i = 0; i < size; i++) { sort(bucket[i].begin(), bucket[i].end()); } int index = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < bucket[i].size(); j++) { array[index++] = bucket[i][j]; } } }