Hot answers tagged

14

Answer to the Performance Issue Anytime there are a list of variables named NAMEi where i is an integer, there is a strong chance that a container such as std::array or std::vector should be used. Sometimes using a table rather than multiple if statements can improve performance. Indexing into an array will prevent the repetitive code that is currently in ...


6

using namespace std; is a bad habit you should avoid. Input Handling: for(int i = 0; i < inputSize; i++) { int tempValue = 0; cout << "Please enter a number between 80 and 85: "; cin >> tempValue; if(tempValue > 79 && tempValue < 86) { inputValue[i] = tempValue; } else { cout << "The ...


3

#level1 global level1 The comment here is not useful, if you have a variable level1, well... that's level1, right? The same goes for all your other comments in the code. You should think of comments as a way to describe why you did things that specific way or the meaning of something. If you need them to describe what is happening, most likely you need to ...


2

Review Since you are building the array yourself, as opposed to you get a source array from a consumer of your method, I don't think you should create a new array, but rather just adapt the source array. This way, you could avoid slice and concat altogether. The number of rotations is an integer. However, reading the description behind the link tells use it'...


2

Welcome to CodeReview! Formatting Get an IDE such as PyCharm or VSCode that's capable of linting. It will give you several "PEP8" suggestions, such as newlines around functions, that will make your code more legible. Some particulars that will be suggested: paddle = Paddle (classes) black = BLACK (global constants) Ball = ball and vice versa - instance ...


2

I was curious about why you kept the initial size inside each of the arrays until I finaly noticed the arrays[i][0] in the check if that array still has elements to proces during the algorithm. If we replace that with arrays[i].length-1 we no longer need to store those. Another major issue, like Nathan pointed out is how many String objects you're creating ...


2

Are you getting the correct output with the recommended complexity? It's been a long time since I've written my own sort but start by confirming that before any of my recommendations below. I suspect str.split(" ") is causing problems for you because you're creating lots of strings which you're about to parse and then throw away. How about parsing the ...


2

This will be cleaner if you implement it as a pure function, which takes the sequence as an argument. You can make [1, 2, 4, 8, 16] a default value for that argument, so that you can start the sequence with nothing. Taking this approach, the function simplifies to: function updateSequence(arr = updateSequence.default) { const last = arr[arr.length-1] ...


1

Since obj.get("geometricSequence"); presumably already contains an array, you can skip the whole shenanigans with the iterator and directly work on that. Also, if you change the order of the if statements at the end you can save some work by not doing slices on an array you eventually gonna replace later anyway. So: updateSequence() { let arr = this.get("...


1

Note: your code doesn't currently compile for at least two reasons: you are not telling the compiler cout and endl live in the std namespace, and you can't declare your arrays start and end because n is not known at compile-time (instead, you'd have to use dynamic memory allocations). In any case, your code smells like your background might be in C (but ...


1

QuickSortArrAscDesc QuickSortArrAscDesc does not work if there are repeat values. Although there are clear improvements over the original, a couple of changes are causing the partitions from combing properly. Current varPivot = arrySource(Int((lngMin + lngMax) / 2), lngSortCol) Original varMid = SortArray((lngMin + lngMax) \ 2, lngColumn) The ...


1

There is not much to review here. This algorithm looks to be as good as it gets. I don't know how much value there is in nitpicking, but here I go: Review The summary tag should be used to describe a type or a type member. Use remarks to add supplemental information (xmldoc summary) -> put the challenge URL in a remarks tag, not in the summary. The ...


Only top voted, non community-wiki answers of a minimum length are eligible