Skip to main content
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
Results tagged with
Search options answers only not deleted user 58193

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.

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 …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
10 votes

Optimization on Sieve of Eratosthenes using vector<bool>

Repeating work already done The biggest problem with your solution is that for each test case, you start over from scratch. This causes you to do up to 10x the work that you need to do. What you sho …
JS1's user avatar
  • 28.6k
8 votes
Accepted

Sufficient implementation of subset sum for 45 min interview

Bug I ran your program, replacing 100 with 6. This should have found the subset {2,4} as a solution but it didn't. Your program searches for contiguous subsets which sum to the given value. I don't …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
6 votes
Accepted

Lock-free SPMC queue

Memory ordering problem This line: if (first == m_last.load(std::memory_order_relaxed)) return false; should be: if (first == m_last.load(std::memory_order_acquire)) …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
6 votes
Accepted

Implementation of a lock-free fixed-sized allocator

ABA problem It looks like your allocator is susceptible to the ABA problem. The allocate() function's compare and exchange is unsafe because the "next" value you are exchanging could be invalid by t …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
4 votes
Accepted

Lock-free bounded stack atomics

Problem 1 Consider that register_idle() is equivalent to this slightly rewritten version: // this function is called by each thread when it is about to sleep void register_idle(size_t thread_id) { …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
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 …
JS1's user avatar
  • 28.6k
4 votes

Sum a list of string numbers

Likely or unlikely? I didn't run your code, but something didn't make sense to me when I was reading it. You use an unlikely macro in several of your loops. But it seems to me that these should be l …
JS1's user avatar
  • 28.6k

15 30 50 per page