69 votes
Accepted

Implementing realloc in C

The code leaves a bad first impression because of how it is formatted. In particular, the extra whitespace between the return type and the function name, and that between the variable's type and its ...
Cody Gray - on strike's user avatar
39 votes
Accepted

Count all vowels in string

An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
Joseph's user avatar
  • 25k
28 votes

Count all vowels in string

I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement. Well, you could put all of those in an array: <...
Sᴀᴍ Onᴇᴌᴀ's user avatar
24 votes

Dungeon Crawl game for the terminal

Overall, this is really well done. You've missed the usual traps of using magic numbers, not creating structures for related items, and other common things. So nice work! I think it could be improved ...
user1118321's user avatar
  • 11.7k
23 votes
Accepted

Can I slim this UTF8-encoding program?

Efficient file I/O By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
G. Sliepen's user avatar
  • 54.6k
22 votes
Accepted

Simple modern C++ string class implementation

Error handling ...
kraskevich's user avatar
  • 5,580
22 votes

Can I slim this UTF8-encoding program?

log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful. As stated in ...
vnp's user avatar
  • 56.4k
20 votes
Accepted

Python code that sorts books

It looks good and readable IMHO. For brownie points, you could: modify the structure a bit. Not every LinkedList will contain books. Similarly, not every ...
Eric Duminil's user avatar
  • 3,960
20 votes
Accepted

COBOL Database Program

ZOMG, that is frightening along so many dimensions. Disclaimer: Within the last decade I wrote lots of python code to parse production COBOL database record formats. And as an undergraduate I had ...
J_H's user avatar
  • 23k
19 votes
Accepted

Customization of memory class C++

Try to be more consistent with naming I'm seeing camelCase, PascalCase and snake_case all mixed together. Pick one style and stick with it. Furthermore, I see redundant things in names like ...
G. Sliepen's user avatar
  • 54.6k
18 votes

Dungeon Crawl game for the terminal

That's an awesome little game! User experience Before we dive into the code, let's talk about the game itself. Random hangs Sometimes, the executable hangs when I ...
Indiana Kernick's user avatar
17 votes
Accepted

Sudoku solution without the use of classes

I see some things that may help you improve your code. Don't abuse using namespace std Putting using namespace std within your ...
Edward's user avatar
  • 66.4k
17 votes
Accepted

Huffman Code in C++

Looks pretty readable and I agree with most of your formatting however there are some things that stand out. using namespace std; Kick this habit before it kicks ...
yuri's user avatar
  • 4,448
16 votes

Naïve RSA decryption in Python

Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do ...
harold's user avatar
  • 9,474
16 votes
Accepted

Implementing a rectangle class

PEP-8 Class names should be CapWords, so instead of rectangle you should have Rectangle. ...
AJNeufeld's user avatar
  • 33.5k
15 votes
Accepted

Enter my Matrix

I will mostly focus on performance in this review because you have specifically asked for it and the other reviews did not cover it yet. Performance The first thing to do when optimizing for ...
5gon12eder's user avatar
  • 4,250
15 votes

Implementing realloc in C

Generally, malloc, realloc and free are all part of the same library. One of the things ...
Neil's user avatar
  • 301
15 votes
Accepted

Phone Book Program in C++

There are a number of things that could be improved, and I hope you find this list of suggestions useful. Don't abuse using namespace std Putting ...
Edward's user avatar
  • 66.4k
15 votes

Count the frequency of items in an array

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. ...
pacmaninbw's user avatar
  • 23.8k
15 votes

Value store ("optional" type)

About these assignments As someone who’s been teaching C++ for 15 holy shit, almost 20 years now, I have to say that these assignments are pretty terrible… especially the “vector” one. (To be clear, I ...
indi's user avatar
  • 11k
14 votes
Accepted

What's the optimal 'pythonic' way to make dot product of two lists of numbers?

The most "pythonic" way of doing this makes use of the sum and zip built-ins: ...
Caridorc's user avatar
  • 27.5k
14 votes
Accepted

Vector implementation, which received unhelpful negative feedback from professor

I understand that some of this class is predicated by your professor; However I will review the code as a whole and you can then choose what can be changed and what cannot be changed. Interface/High-...
Emily L.'s user avatar
  • 16.6k
14 votes
Accepted

Checking for parentheses balance in C

Bugs The loop header is wrong: for(i=0;line[i]!=NULL;i++){ Here, you want to scan until you find a byte with ASCII value 0 (also called an ASCII NUL, and ...
200_success's user avatar
14 votes

Python code that sorts books

A little late here as I just got back in front of a non-mobile device, so let me try to add some new points: Most importantly (with the caveat that I'm super pedantic), the format of this assignment ...
Bailey Parker's user avatar
14 votes

Egg size Prompt Box

The parseInt(eggWeight); calls are not doing anything, because you are not using its return value. And since you aren't using the return value, the comparisons are ...
RoToRa's user avatar
  • 11k
13 votes

Implementing realloc in C

You are checking if malloc succeeded before calling memcpy, but not before calling memset. ...
D. Jurcau's user avatar
  • 3,010
13 votes

Checking for parentheses balance in C

The idea is correct, the implementation is not. Upon exiting the loop you need to test for pilepointer == -1. Otherwise, the strings like ...
vnp's user avatar
  • 56.4k
13 votes

Egg size Prompt Box

Since you already checked > 69 , if you get to the next else if you don't need to check that it is ...
user985366's user avatar
  • 1,705
13 votes
Accepted

Toggle 2 LEDs using a timer XMEGA-A3BU Xplained

The optimizer has a habit of optimizing out my timing loops. This is (a) a non-surprise, and (b) somewhat of a red flag when it comes to coding practice. If you're writing timing loops that attempt ...
Reinderien's user avatar
  • 61.2k

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