Guard against the passage of the count

I have a structure in C that contains an array on which I perform stack operations.

If the stack is full, I need to prevent the element from being clicked at the end of the array and return an error condition.

Is it better to include the stack size as a structure element and pass that number of elements to the stack_push () function, or should I have a watch element at the end of the stack array?

+4
source share
2 answers

How are you going to implement your function stack_push()?

, , (, NULL, ). , O (N).

, O (1) push ( pops). , , .

, .

+4

? , , , , . , , .

, , NULL , . , , , , .

, , , , .

+1

Source: https://habr.com/ru/post/1535099/


All Articles