Created
June 6, 2017 18:54
-
-
Save RdlP/c3b70714bcaca41419e954976e516df4 to your computer and use it in GitHub Desktop.
This file contains 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_MAXSIZE 50 | |
struct _Stack | |
{ | |
Node *stk[STACK_MAXSIZE]; | |
int top; | |
}; | |
typedef struct _Stack Stack; | |
struct node{ | |
float freq; | |
unsigned char symbol; | |
int height; | |
int depth; | |
unsigned char code[20]; | |
struct node *left,*right; | |
}; | |
typedef struct node Node; | |
void push (Stack *s, Node* node) | |
{ | |
if (s->top == (STACK_MAXSIZE - 1)) | |
{ | |
printf ("Stack is full\n"); | |
return; | |
} | |
else | |
{ | |
s->top = s->top + 1; | |
s->stk[s->top] = node; | |
} | |
return; | |
} | |
Node* pop (Stack *s) | |
{ | |
Node* node; | |
if (s->top == - 1) | |
{ | |
printf ("Stack is Empty\n"); | |
return NULL; | |
} | |
else | |
{ | |
node = s->stk[s->top]; | |
s->top = s->top - 1; | |
} | |
return node; | |
} | |
int empty(Stack *s){ | |
if (s->top == -1){ | |
return 1; | |
} | |
return 0; | |
} | |
void init_Stack(Stack* s){ | |
s->top = -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment