Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81350 / parser / colapser / stack.c
blob: c6edd42811957307e1ba3744ade355b8d0462e60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "stack.h"

int stack[MAXSIZE];
int top = -1;

int isempty() {

   if(top == -1)
      return 1;
   else
      return 0;
}

int isfull() {

   if(top == MAXSIZE)
      return 1;
   else
      return 0;
}

int peek() {
   return stack[top];
}

int pop() {
   int data;

   if(!isempty()) {
      data = stack[top];
      top = top - 1;
      return data;
   } else {
      printf("Could not retrieve data, Stack is empty.\n");
   }
}

int push(int data) {

   if(!isfull()) {
      top = top + 1;
      stack[top] = data;
   } else {
      printf("Could not insert data, Stack is full.\n");
   }
}

char* concatenate(char* first, char* second) {
    int firstlen = strlen(first);
    int secondlen = strlen(second);
    char* result;
    result = malloc(firstlen + secondlen + 1);
    strcpy(result, first);
    strcat(result, second);
    return result;
}