giftsuper.blogg.se

Generic linked list stack
Generic linked list stack













Always return from main() even though C allows the return statement to safely be omitted.I don't think the person who wrote that billion dollar bug was a rookie, but rather an arrogant veteran insisting on not using braces, for no good reason. See Apple's "goto fail" bug as one perfect example. People who don't do this will write bugs, sooner or later. The is_empty function does not alter the stack, so that argument should express that notion by using the const keyword: bool is_empty(const pstack *s) (aka "compound statements") after every single if or loop. One might argue (correctly!) that because it include stack.h that it's included indirectly, but I'd advocate that it's also in the implementation file so that it's obvious that the bool used there is the stdbool.h version. On the other hand, it uses the bool from stdbool.h but doesn't include it directly.

generic linked list stack

The stack.c file has #include but it appears to me that no functions from it are needed. Generic allows us to store data of any data type such as String, Integer, Float, etc., in the linked list. I see some things that may help you improve your code. LinkedList can not contain only one type of data type, but it can contain String, Integer, Float, etc., so to overcome this, we have to use generic list which can store values of any type. Struct Stack *new_node = malloc(sizeof(struct Stack)) Void push(struct Stack **s, void *new_num) * pstack which are pointers to pointers to Stack structures. Clients that pull in stack.h will be able to declare variables of type

generic linked list stack

* We declare a pointer to a Stack structure thereby making use of incomplete

generic linked list stack

I tried to implement a generic stack in C using void pointers and tried to keep it as simple as possible by delegating all responsibility to the caller of the functions and avoiding more sophisticated approaches.















Generic linked list stack