Skip to content

Instantly share code, notes, and snippets.

@RdlP
Created June 6, 2017 18:54
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 RdlP/c3b70714bcaca41419e954976e516df4 to your computer and use it in GitHub Desktop.
Save RdlP/c3b70714bcaca41419e954976e516df4 to your computer and use it in GitHub Desktop.
#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