-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellsort.h
More file actions
104 lines (94 loc) · 3.77 KB
/
shellsort.h
File metadata and controls
104 lines (94 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// Created by Speci on 7/29/2024.
//
#ifndef PROJECT3_SHELLSORT_H
#define PROJECT3_SHELLSORT_H
#endif //PROJECT3_SHELLSORT_H
//
// Created by Speci on 7/29/2024.
//
#pragma once
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
using tupInfo = tuple<string,string,string,string,string,string,string,string,string,string,string,string,
string,string,string,string,string,string,string,string,string,string,string,string>;
// Based on pseudo-code from TA notes
void ShellSorting(vector<tupInfo> &dataInfo, int choice){
// first, figure out which choice we are sorting by
// 9 = dance-ability
if(choice == 9) {
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<9>(dataInfo[k - i]) > get<9>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}else if(choice == 10){
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<10>(dataInfo[k - i]) > get<10>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}else if(choice == 14){
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<14>(dataInfo[k - i]) > get<14>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}else if(choice == 15){
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<15>(dataInfo[k - i]) > get<15>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}else if(choice == 16){
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<16>(dataInfo[k - i]) > get<16>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}else if(choice == 17){
// start with a loop that's has a 1/2 gap, slowly closing the gap each time
for (size_t i = dataInfo.size() / 2; i > 0; i /= 2) {
for (int j = i; j < dataInfo.size(); j += 1) {
tupInfo temp = dataInfo[j];
int k;
for (k = j; k >= i && get<17>(dataInfo[k - i]) > get<17>(temp); k -= i) {
dataInfo[k] = dataInfo[k - i];
}
dataInfo[k] = temp;
}
}
}
}