Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag.
2
votes
Simple Single Linked List - follow up
push_back() simplification
Your push_back() function seems overly complicated. This part:
if (m_tail != nullptr)
{
auto at = iterator(m_tail);
auto node = new Node;
node->next = at.m …
5
votes
Insertion Sort in C++
Reducing number of writes
Right now, you swap neighboring elements until the newest element reaches its proper place. This takes 2n array writes to move an element n spots. Instead of swapping, you …
0
votes
An attempt at inheritance (Geometric Shapes)
Bug
Your formula for the surface area of a Box is wrong:
double surfaceArea() const override { return (2*length*height) + (4*width*height); }
It should be:
double surfaceArea() const override { ret …
4
votes
Binary Search Tree - C++
Remove
I find it interesting that you have a special case for removing the root where if it has one child, you reroot the tree on the child. That is actually a good move because it always reduces th …
4
votes
Weaving an array
More efficient way
Your current algorithm runs in \$O(N^2)\$ time. At the time I started thinking about this, I did not read Jerry Coffin's link that demonstrated an \$O(N)\$ solution, so I came up …
5
votes
Accepted
Lock-free, multiple consumer, multiple producer queue
ABA problem
I was able to break your queue (but it wasn't easy). I inserted some code to freeze one thread here in consume():
do{
// The divider's next pointer points to the next node wit …
4
votes
Accepted
Detecting cycles
Too complex
With the problem constrained to:
The elements of the sequence are integers in range [0, 99]
The length of the sequence is in range [0, 50]
the program should be very simple. Instead, yo …
11
votes
Accepted
Largest palindrome that can be made from a product of 2 3-digit numbers (Project Euler 4)
Speeding things up
There are several things you could do to speed things up:
Instead of looping from 100..999, go from 999..100 instead. That way, if you find a palindrome, you can break from the j …
11
votes
N closest points to the reference point
Faster sorting
If the only purpose of the distance computation is for comparison, then you can speed it up by removing the call to sqrt(). You'll end up comparing the squares of the distances, which …
6
votes
Quad-sort: 4 sorting methods in one C++ file
Bug
This line in your quicksort isn't right:
int pivot = toSort[(rand() % endPtr - beginPtr + 1) + beginPtr];
It should be:
int pivot = toSort[rand() % (endPtr - beginPtr) + beginPtr];
Notice that …
4
votes
Accepted
Naive lock free work stealing queue
Pop() has problem
Consider what happens if your queue is in the following state with two jobs:
m_top = 0
m_bottom = 2
The owner thread calls pop(), and loads in to local variables:
top = 0
bott …
6
votes
Searching for three positive integers as a solution to an equation
Stop printing so much
I ran your program and found that it spent most of its time printing every single combination (even though none of them were solutions). After I removed the line that prints the …
1
vote
Lock-free MultiConsumer/MultiProducer queue
Bug
When you pop an element off, you increment iHead before reading the return element from elements. If that thread pauses between the increment and the read, another thread can push a new element i …
2
votes
Divide and Conquer algorithm for counting inversions
More clear by using extra argument?
If you passed in a count by reference to each function, and each function incremented this count instead of returning a new count in a tuple, the code might look cl …
3
votes
Accepted
Find non duplicateTriangle Triplets from a list of given numbers
Not an O(N^2) algorithm
You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.
For each pair, you loop across the original vector of N elements.
Outer loop = O( …