Thanks for that. I'll add it to my list of fundamental algorithms
It's really fascinating watching someone type code
a) Do not cast the return value of malloc()
b) Preferably do not use sizeof(node) -- use sizeof (*temp)
c) Functions should do one thing; not, for example, a function called push() should not be getting the value to push from the user
d) Check the return value of scanf()
e) If your function does not take any parameters then say so. Don't use void push(), use void push(void). This is C, not C++ and the two declarations have slightly different semantics. By the way push(), for example, *should* have a parameter (see item (c))
f) <malloc.h> is a non-standard header; use <stdlib.h>
Those are just the mistakes that jumped out. I'm not going to type in the program but are you sure it even works as intended?
Last edited by Hodor; 10-26-2017 at 01:26 AM.
I didn't like the fact that while watching him/her type. as they moved down their piece of E-Paper. I couldn't scroll back up to check what had been written using my mouse wheel.
From a guy who has to press compile TWICE to figure out that struct isn't spelled strcut.
And to add to Hodor's list - global variables.
Nothing to see folks.
I'm done with this muppet posting mis-information.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.