Skip to content
Snippets Groups Projects

add function stack_push

Merged richarda.tyarks requested to merge 5-add-push-function into main
2 unresolved threads

just like the tittle. Thanks for the review. ;D

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
stack.c 0 → 100644
1 #include "stack.h"
2
3 void stack_push(stack *s, int val)
  • Also if you could merge with main and correct conflicts this would help me.

  • richarda.tyarks added 28 commits

    added 28 commits

    Compare with previous version

  • added 1 commit

    • 5401bb7f - change variable name val into value in function : stack_push

    Compare with previous version

  • richarda.tyarks approved this merge request

    approved this merge request

  • richarda.tyarks unapproved this merge request

    unapproved this merge request

  • added 1 commit

    Compare with previous version

  • Sorry Sir, I completely forgot to see your review, since I never check my student mailbox. Sorry again ^^ '

  • 1 #include "stack.h"
  • orestis.malaspin
  • added 1 commit

    Compare with previous version

  • Almost young padawan. Capacity is never changed!

  • added 1 commit

    Compare with previous version

  • noooooooooooooooooooooooooo.....

    we want to allocate twice the current capacity. and also change the capacity variable inside the struct. don't we?

  • if (s->top == DEFAULT_CAPACITY-1) { assert(s->data = realloc(s->capacity * 2 * sizeof(int))); } like that ? but in this case we can enlarge the stack only once ?

  • No no.

    What I mean is that you have to reallocate to twice the CURRENT capacity. Then change the capacity variable too.

    In this example you:

    1. Change the capacity of data only once for all (when top == DEFAULT_CAPACITY-1 which happens only once if you continuously push).
    2. Never change the capacity variable in your stack.
    Edited by orestis.malaspin
  • haaaaa yes it's just add "s->capacity=s->capacity * 2;" after the realloc for update the new capacity limit

  • added 1 commit

    Compare with previous version

  • added 1 commit

    • 515a3006 - https://www.youtube.com/watch?v=dQw4w9WgXcQ

    Compare with previous version

  • mentioned in commit 287ed7af

  • mentioned in issue #5 (closed)

  • Please register or sign in to reply
    Loading