Skip to content

Instantly share code, notes, and snippets.

@uhmseohun
Created July 23, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhmseohun/da54aaad9e3048c03b6e8bd3976a5a21 to your computer and use it in GitHub Desktop.
Save uhmseohun/da54aaad9e3048c03b6e8bd3976a5a21 to your computer and use it in GitHub Desktop.
#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