9

A few notes to add to the existing answer(s): It is not wrong use not in place of ! but I'd like to claim that most programmers will find it odd. Shorthand operators are much more common and likely make parsing the code faster for most readers. It appears that your algorithm is not exact (i.e., it is not guaranteed to find an optimal coloring for every ...


7

GenericList.h and GenericList.c Generally this is excellent code as long as it is a stack you want. It seems that what is created is really a generic stack implemented on a linked list rather than a generic linked list. If it was truly a generic linked list there would also be an append function and the delete node function would have to be smart enough to ...


5

Overall Good. Personally I don't like building containers using smart pointers. Containers and smart pointers are the techniques we use to manage memory for objects (singular or plural respectively). As such they should both manage their own memories correctly. But other people do it (use smart pointers) so I don't see it as a big deal; but I think you ...


5

The answer uses this structure declared in the program: typedef struct ListNode { // Basic Node data structure of a Linked List int val; struct ListNode* next; } node_t; Symbolic Constants for Return From main() and exit() The program is already including <stdlib.h>. There are two system defined macros or Symbolic Constants supplied by &...


5

Your test code may cover all the main code, but it has a huge drawback. It won't fail if you make a programming mistake in the main code. Instead of printing the values from the list, you should rather assert that they are exactly what you expect. Instead of writing the boring if (status != GEN_LIST_NO_ERR) each time again, you should extract that code ...


5

It reads like list.cmp is required to be initialized, otherwise genListSearchNode is not meaningful. In that case, I would suggest checking cmp's value in function genListNew. If it is null, return a null ptr. Then in function genListSearchNode, we could have checked list->cmp as part of the parameter validations; exit early if list->cmp is null. you ...


4

High level comment: you have chosen your list to own its data (as you allocate/free the data behind list elements inside this code) but without compile-time checking of the type of the data being fed to it. Now this is actually fine if the user code is very careful with the data pointers and size inputs. But that is an assumption that you might not want to ...


4

The input asking for which value to delete can/should be placed in a separate function. Then the function to remove the nodes can take that value as a parameter. The two malloc calls for temp and curr near the top are completely unnecessary and just leak memory. You want to remove nodes, so you shouldn't have to allocate any memory. If your list consists ...


3

String parsing You are right that C++ slightly lacks some convenient features for string parsing. If you were not trying to count lines as well as find words, then a single while loop with: inFile >> s; would have sufficed, because streaming will terminate on whitespace by default. But because you want to count lines, you need the 2 loops and ...


3

The description of resvalAppend() is beside the point to the point of being misleading: there is no source code entity resval there is one recursive call, at most (serving no purpose I can discern) overflow no longer is a global variable added to the result Linked List better be appended to avoid confusion with the arithmetic operation at hand (almost) ...


3

There's enough to review in just the appendNode() function; much of this applies to the rest of the code, too. Don't cast the result of malloc() like this: node = (node_t*)malloc(sizeof(node_t)); If declared properly, malloc() returns a void*; that's assignable to any pointer type. (If not declared properly, fix that first). Also, instead of making ...


3

As Winston said, adding an iterator will enable you to add quite a lot of functionality to this list quite easily. and can be done by wrapping your list in a tuple struct and implementing the desired traits - the Linked List Guide as recommended by lucarlig is a great resource and shows you how to do this A couple of other things to think about: Think ...


3

Whenever you perform input like this, don't discard the result of scanf(): int x; scanf("%d", &x); At the very least, bail out if invalid input is provided: int x; if (scanf("%d", &x) != 1) { fputs("Input failed!\n", stderr); return NULL; } A more sophisticated approach would consume the rest of the line (scanf("%*[^\n]")) and re-try the ...


3

A function that asks its parameter is not really usable, but let's assume it is for the code review question. The main error is starting right away to declare and create variables. Allocation certainly is not needed when deleting nodes. Try postpone creating variables until one needs them. Thus reducing the effort to read the code, and being sure one needs ...


3

node_t *funzione(node_t *head){ This is a weird name for a function to remove a node. The naming should reflect what the operation does, not what it is. int x; node_t *temp = head; node_t *curr = head; The way the rest of your function works, it assumes that temp points to the node after curr in the list, assigning them to the same node ...


2

Bug: Returning a free'd pointer! After freeing a pointer, do not use it. free(head); printf("La lista adesso e' vuota. Finito\n"); // return head; return NULL; Is there anything else that can be improved? Rather than 2 or 3 cases to handle an empty list, list of only matches or mixed list, consider a code simplification. ...


2

feedback on speed and optimization O(n) to O(1). Consider changing appendNode() from O(n) to O(1). Rather than have a link-list point to the head, let the LL point to the tail and the tail point to the head. To append to the end of the list or to the front is a similar O(1) operation. // add to the end or front of the LL void addNode(node_t** ref, int ...


2

To be brief on your three points. You can try to omit extra variables and trust the function boundary. For example, your code starts with this excellently named function: def is_Number(value): is_number = False try: float(value) except ValueError: pass else: is_number = True return is_number or more concisely, ...


2

Strategies It would have been good to summarize the key points and strategies of the different implementations. Mostly for yourself, to clarify your thinking and solidify your understanding. Secondly for reviewers :-) Let me take a jab at that now. Solution 1 while there are lists to merge find the minimum head and merge it update the list with the ...


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