13 votes

Unidirectional linked list in C

Bug Test code better. ...
11 votes

Unidirectional linked list in C

Think about the failure cases. For example: struct node *list = malloc(sizeof(struct node)); list->data = data; list->next = NULL; return list; If ...
  • 60.7k
7 votes
Accepted

Intrusive linked list in C

You are quite right that intrusive linked list and opaque data-structure are mutually exclusive. That is, you could hide all the list-stuff in each node behind a pointer, but the extra-allocation ...
6 votes

Check if parentheses are balanced using a stack implemented with a linked list

<bits/stdc++.h> is not a standard header. It's an implementation detail of the compiler you're using, and can be changed or removed without notice. Include ...
  • 60.7k
5 votes

Check if parentheses are balanced using a stack implemented with a linked list

Stop processing on first unbalanced closing When an unbalanced closing symbol is found, the program happily continues until the end of the input, even when the answer is already known. Consider for ...
  • 110k
5 votes

Unidirectional linked list in C

You might consider to abbreviate struct node with a typedef name: ...
  • 3,246
4 votes

Unidirectional linked list in C

Interfaces Consider the work that your contains function does compared to the information it returns. It finds the first position that has the value in question. ...
4 votes

Unidirectional linked list in C

A serious error everybody appears to fix without comment: push_back() allocates memory and forgets to initialize some of it. Specifically, it fails to write: ...
  • 1,178
3 votes

Unidirectional linked list in C

Some suggestions follow. 1/ Comment your code. It won't affect at all how the code does its job (unless you do something silly like comment out a vital line of code), but it will affect the ability to ...
  • 141
2 votes
Accepted

Linked List implemented in C++

Defeating namespacing Don't using namespace std; ever! It pollutes your local namespace. If the standard ever added std::Node, ...
  • 32.2k
2 votes

Simple slab allocator in C

Naming things Names are mostly OK, but there are some inconsistencies. For example, new_slab() with an underscore versus ...
  • 35.7k
1 vote

Unidirectional linked list in C

make sure there are no possible memory leaks Advice on testing: Have allocation & disposal functions increasing & decreasing an instance count as ...
  • 4,958
1 vote

Check if parentheses are balanced using a stack implemented with a linked list

Do not use global variables. Global variables cause an "effect at a distance" which makes reasoning about code difficult. Instead, variables should have as tight a scope as possible, and the ...
  • 3,553

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