commit de6d004ee755933e9409542da63add4fe9abab06
parent 5bbd04378441ec61d28eceefadb8e591aca47498
Author: Victor Adamson <a20vicad@student.his.se>
Date: Mon, 27 Nov 2023 16:16:06 +0100
Merge branch 'master' of https://github.com/LindholmLabs/DSA-Assignments
Diffstat:
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/Problem1/Problem1.cpp b/Problem1/Problem1.cpp
@@ -1,5 +1,5 @@
// Problem 1: Bucket Sort
-// Description: Find the target number in the unsorted vector
+// Description: Sort a vector using a modified version of bucket sort.
// Course: IT405G - Datastructures and Algorithms
// Authors: William Lindholm, Lili Tran, Victor Adamson
// Date: 13-11-2023
@@ -36,7 +36,7 @@ int main()
/*
* Function: bucketSort
- * Sort an unsorted vector using bucket sort
+ * Sort an unsorted vector using a modified version of bucket sort
* @param v: the unsorted vector
* @return: the sorted vector
*/
@@ -59,10 +59,12 @@ vector<int> bucketSort(vector<int> v)
// Append from buckets in order to sorted vector
for (int i = 0; i < (int) w.size(); i++)
{
+ //check if bucket is empty
if (!w[i].empty())
{
- for (int x : w[i]) {
- sorted.push_back(x);
+ // loop through each bucket
+ for (int value : w[i]) {
+ sorted.push_back(value);
}
}
}