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

The c++ code for implementing shell sorting and bucket sorting algorithms as part of an assignment for the data structures course csm 388. The code includes the implementation of the shellsort function for shell sorting and the bucketsort function for bucket sorting.

Typology: Lecture notes

2019/2020

Uploaded on 02/21/2020

bismark-osei
bismark-osei 🇬🇭

5

(1)

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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]; } } }