Fixed length().
This commit is contained in:
parent
f0aa621e69
commit
84383a3275
@ -19,12 +19,14 @@ bool empty(struct stack *stack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int length(struct stack *stack) {
|
int length(struct stack *stack) {
|
||||||
|
struct stack *iterator = stack;
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
|
||||||
if (!empty(stack)) {
|
if (!empty(stack)) {
|
||||||
length = 1;
|
length = 1;
|
||||||
while (stack->next != NULL) {
|
while (iterator->next != NULL) {
|
||||||
length++;
|
length++;
|
||||||
|
iterator = iterator->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user