28th Jan 2021, 5:48 AM
Nivas Reddy
Nivas Reddy - avatar
3 odpowiedzi
+ 3
you cannot declare variable inside an if-else statement: int pop(){ int result; if(stack[top]==empty) return stack_empty; else result=stack[top]; top--; return (result); }
28th Jan 2021, 5:57 AM
visph
visph - avatar
+ 1
stack[top] == empty will compare the stack element at index 'top' with empty (instead of the stack element counter). "you cannot declare variable inside an if-else statement" In this context 'result' cannot be declared in the if-else statement because it's returned by the function. I'd personally drop the temp variable (and maybe even reduce it down to a one-liner). return (top > empty) ? stack[--top] : stack_empty; Source: https://code.sololearn.com/cA136A7a1694
28th Jan 2021, 12:04 PM
Mike A
Mike A - avatar
0
visph Seems to be simple one Thanks ❤️
28th Jan 2021, 6:01 AM
Nivas Reddy
Nivas Reddy - avatar