Created
July 23, 2020 13:25
-
-
Save uhmseohun/da54aaad9e3048c03b6e8bd3976a5a21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define STACK_SIZE 10 | |
char stack[STACK_SIZE]; | |
int top = -1; | |
int isFull() { | |
return top >= STACK_SIZE - 1; | |
} | |
int isEmpty() { | |
return top <= -1; | |
} | |
void push(char data) { | |
if(isFull()) exit(0); | |
stack[++top] = data; | |
} | |
char pop() { | |
if(isEmpty()) exit(0); | |
return stack[top--]; | |
} | |
char peek() { | |
if(isEmpty()) exit(0); | |
return stack[top]; | |
} | |
int getSize() { | |
return top + 1; | |
} | |
void print() { | |
printf("{ "); | |
for (int i=0; i<=top; ++i) { | |
printf("%c", stack[i]); | |
if(i < top) printf(", "); | |
} | |
printf(" }\n"); | |
} | |
int main() { | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment