Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
10 votes
Accepted

Redefining queue with different front and rear

Your teacher is right. This is not a good FIFO. Is there any problem in my code ? We're not ready to go there, yet. Let's first worry about problems with the design. We want to implement a queue ...
J_H's user avatar
  • 27.4k
9 votes

Linked list and array list performance comparison in C

typedef struct Node *Node; I strongly recommend against this. Whether something is a pointer or not (or in general, the number of indirections) is an extremely ...
user555045's user avatar
  • 9,794
9 votes

Automate character search in C

index type You seem to choose (signed) long or int apparently at random when writing a loop. Prefer (unsigned) ...
J_H's user avatar
  • 27.4k
8 votes

Count the number of mismatches between two arrays

At first I wasn't going to do this, in part because of the cross-posted version of this question to Stack Overflow being closed as duplicates of various pre-existing questions about counting bytes, ...
user555045's user avatar
  • 9,794
8 votes
Accepted

Merging sorted integer arrays (without duplicates)

This is a two-way merge. preconditions merge_arrays([1, 2, 3], [5, 7, 1]) I was a little surprised to see that non-monotonic ...
J_H's user avatar
  • 27.4k
8 votes

Merging sorted integer arrays (without duplicates)

The suggestions by @J_H are excellent, as usual. From an algorithmic perspective, though, a two-way merge is a useful exercise, so I think it is valuable to keep to the original algorithm. Be clear ...
Matthieu M.'s user avatar
  • 5,137
7 votes
Accepted

Automate the boring stuff with python - Character picture grid

In Python, you rarely need to iterate using indexes. Iterate directly over the values themselves, not their indexes. [The latter is what programmers working in poorer languages have to do.] Question ...
FMc's user avatar
  • 12.7k
7 votes
Accepted

Linked list and array list performance comparison in C

Most of the code looks good, apart from the misleading typedef that harold's answer addresses. In this review, I'll be assuming that we fix that problem. I just ...
Toby Speight's user avatar
  • 75.7k
7 votes

Automate character search in C

The first thing that strikes me is that you haven't shown your tests of the code. Although you don't have access to the scoring system, you can easily prepare some basic tests of functionality that ...
Toby Speight's user avatar
  • 75.7k
6 votes

Redefining queue with different front and rear

I agree with J_H that this needs to be redesigned, but there are a few basic issues in the code. It is never a good idea for a number that can be an index into an array to ever go negative, this can ...
pacmaninbw's user avatar
  • 23.8k
6 votes

Small code exercise with 3D arrays in C

I mostly like your style, but I think the code is too complex for what it does right now. Instead of addressing the complexity by writing a lot of comments, look for ways to simplify the code so that ...
Pkkm's user avatar
  • 190
6 votes

Small code exercise with 3D arrays in C

Don’t Write “Three-Star Code” This is the major issue. An array of pointers to pointers to pointers to arrays is just a terrible data structure, and you should never use it. It uses memory ...
Davislor's user avatar
  • 7,536
6 votes
Accepted

A fixed-size dynamic array

Note: although the question is tagged C++17, I'm going to use some C++20 or later features in my review, as this simplifies the code. Many of my suggestions can be written in C++17, but at the ...
Toby Speight's user avatar
  • 75.7k
6 votes

Count the number of mismatches between two arrays

You Don’t. But, .... Any modern optimizing compiler is going to vectorize that loop into fast SIMD code All the twentieth-century tips and tricks you’ll find out there that tell you to pack the ...
Davislor's user avatar
  • 7,536
6 votes

Automate character search in C

General Observations For the most part the code is portable which is good, however, variable length arrays that were introduced in C99 were made optional in C11 which means they may not compile in all ...
pacmaninbw's user avatar
  • 23.8k
6 votes
Accepted

Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms

Algorithm aside, it's easier to reason through the code if you: Use enumerate(q, 1) since the stickers are 1-indexed (to avoid the +1's) Use semantic variables <...
tdy's user avatar
  • 1,350
5 votes

Automate the boring stuff with python - Character picture grid

Currently you are making assumptions in logic_grid about grid. With the current setup it's fine, but if later ...
depperm's user avatar
  • 937
5 votes
Accepted

Optimizing Subarray Removal: Can the Removal Process be Enhanced for Better Efficiency?

The loop while (q < q2 && *p == *q) { p++; q++; } may access p out of bounds. A fix ...
vnp's user avatar
  • 56.5k
4 votes

Leetcode - First Unique Character in a String

Pay attention to Constraints While cracking algorithmic problems, pay very close attention to the constraints of the problem at hand. They can often give valuable clues on how to attack the problem. ...
Alexander Ivanchenko's user avatar
4 votes

Quickselect algorithm implementation and its time-complexity

int []arr = {13,9,8,3,3,4,6,11,3,5}; Naming an array to arr is not really helping the reader/maintainer of the codebase Try to ...
Peter Csala's user avatar
  • 9,134
4 votes

Automate the boring stuff with python - Character picture grid

You can use zip to transpose the itearble of iterables. Like this: print('\n'.join(''.join(i) for i in zip(*grid))) (and this ...
Alexey Burdin's user avatar
4 votes

Small code exercise with 3D arrays in C

This comment: ...
Reinderien's user avatar
  • 62.1k
4 votes

Counting duplicate elements in two sorted arrays

Looks good and correct, I'd have only two suggestions: Your function is called _find_Duplicates but it actually counts them, so ...
Marvin's user avatar
  • 560
4 votes
Accepted

Reusable storage for array of objects

Use the return value of placement-new In your code you write: T* tmp = reinterpret_cast<T*>(paligned); However, at this ...
G. Sliepen's user avatar
  • 56.8k
4 votes

Chessboard configuartions with no possible capture on the next move

Naming things Your code is full of one-letter variables and variables with very short names. It makes it very hard to understand the code. Consider this line on its own: ...
G. Sliepen's user avatar
  • 56.8k
4 votes

Automate character search in C

(This isn't so much a code-review as what I was going to comment on other answers that mentioned optimized asm libc implementation of memchr and so on. And/or how ...
Peter Cordes's user avatar
  • 3,346
4 votes

A dynamic array with an iterator compatible with std::sort

You could separate test-code and the header-only library-code you developed in your presentation. Doing so would make it clear that you aren't polluting consumers global scope with ...
Deduplicator's user avatar
  • 19.3k
4 votes

Fill missing data in between available data with default value

sorted input function fillEmptyData(data: typeof rawData) { I don't believe typeof rawData makes any sorting guarantees. ...
J_H's user avatar
  • 27.4k
3 votes

Counting duplicate elements in two sorted arrays

The first thing I notice about the single function presented is the lack of a doc comment. Then again it is private, and readable enough I think I get what it does, ...
greybeard's user avatar
  • 6,456
3 votes
Accepted

Shrink an array of double elements (uniformly)

I don't understand the first loop. It seems like a successive approximation calculation for the step size, but that shouldn't be necessary. Instead, we know that you have two defined endpoints of a ...
Reinderien's user avatar
  • 62.1k

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