DSA-Assignments

Log | Files | Refs | README

commit 6715b6b6aaa31af89e9304efe7c7f3909eb6be40
parent c912cf66e10fa958b148d5cdaadc2b97f88baec7
Author: William Lindholm <a22willi@student.his.se>
Date:   Mon, 27 Nov 2023 15:10:17 +0100

Small changes and improvements to variable names and comments.

Diffstat:
MProblem1/Problem1.cpp | 10++++++----
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 @@ -34,7 +34,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 */ @@ -57,10 +57,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); } } }