SHARE
TWEET

Untitled

a guest Jun 19th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void StackPush(stackT *StackP, int element)
  2. {
  3.     if(StackP->elems == StackP->maxSize)
  4.     {
  5.         int *moreContents = (int*)realloc(StackP->contents, (StackP->maxSize+10)*sizeof(int));
  6.         StackP->contents = moreContents;
  7.     }
  8.     StackP->elems = StackP->elems+1;
  9.     StackP->lastElem = element;
  10.     StackP->contents[++StackP->top] = element;
  11. }
  12.  
  13. int StackPop(stackT *StackP)
  14. {
  15.     int lastTop;
  16.     if(StackIsEmpty(StackP))
  17.     {
  18.         fprintf(stderr, "Can't pop element form stack: stack is empty\n");
  19.         exit(1);
  20.     }
  21.     lastTop = StackP->top -1;
  22.     StackP->elems = StackP->elems-1;
  23.     if(lastTop == -1)
  24.         StackP->lastElem = 0;
  25.     else
  26.         StackP->lastElem = StackP->contents[lastTop];
  27.     return StackP->contents[StackP->top--];
  28. }
RAW Paste Data
Want to get better at C?
Learn to code C in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top