logo

Crowdly

Adott az alábbi Stack típus: typedef struct {     int capacity;     int ...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Adott az alábbi Stack típus:

typedef struct {

    int capacity;

    int top;

    int *elements;

} Stack;

Továbbá a következő függvények:

  • createStack(capacity, &stack) – létrehoz egy üres vermet adott kapacitással

  • push(&stack, x) – hozzáadja az x elemet a verem tetejére, ha nincs tele

  • pop(&stack) – eltávolítja és visszaadja a legfelső elemet

  • peek(&stack) – visszaadja a legfelső elemet, de nem távolítja el

Mit ír ki az alábbi program?

int main(void)

{

    Stack stack;

    createStack(4, &stack);

    push(&stack, 10);

    push(&stack, 20);

    printf("%d ", peek(&stack));

    printf("%d ", pop(&stack));

    push(&stack, 30);

    printf("%d ", peek(&stack));

    printf("%d ", pop(&stack));

    printf("%d ", pop(&stack));

}

More questions like this

Want instant access to all verified answers on moodle.ms.sapientia.ro?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!