C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
stack.c File Reference

Contains definitions of routines supported by stack. More...

#include "stack.h"

Go to the source code of this file.

Functions

bool is_stack_full (t_gen d)
 
Check stack full More...
 
bool is_stack_empty (t_gen d)
 
Check stack empty More...
 
int stack_size (t_gen d)
 
get stack size More...
 
t_gen stack_push_arr_up (t_gen d, t_gen data)
 
Push an element into up growing stack More...
 
t_gen stack_pop_arr_up (t_gen d)
 
Pop an element from up growing stack More...
 
t_gen stack_push_arr_down (t_gen d, t_gen data)
 
Push an element into down growing stack More...
 
t_gen stack_pop_arr_down (t_gen d)
 
Pop an element from down growing ll stack More...
 
t_gen stack_push_ll (t_gen d, t_gen data)
 
Push an element into a link list based stack More...
 
t_gen stack_pop_ll (t_gen d)
 
Pop an element from a link list based stack More...
 
t_gen stack_peek (t_gen d, int idx)
 
void stack_print (t_gen d)
 
print_stack_info More...
 
void destroy_stack (t_gen d)
 
Destroy instance of the stack More...
 
t_gen create_stack (char *name, int max_size, e_stacktype stype, t_dparams *prm)
 
Create an instance of stack More...
 

Variables

f_gen2 stack_push [] = {stack_push_ll, stack_push_arr_up, stack_push_arr_down}
 Look Up function ptrs for pushing to stack. More...
 
f_gen stack_pop [] = {stack_pop_ll, stack_pop_arr_up, stack_pop_arr_down}
 Look Up function ptrs for poping to stack. More...
 

Detailed Description

Contains definitions of routines supported by stack.

Definition in file stack.c.

Function Documentation

◆ create_stack()

t_gen create_stack ( char *  name,
int  max_size,
e_stacktype  stype,
t_dparams prm 
)


Create an instance of stack

Parameters
name- Name of stack instance
max_size- Max size of stack instance
type- Type of stack to be created
prm- Data type specific parameters
Returns
- Pointer to instance of stack

Definition at line 37 of file stack.c.

◆ destroy_stack()

void destroy_stack ( t_gen  d)


Destroy instance of the stack

Parameters
d- Pointer to instance of stack
Returns
- NA

Definition at line 327 of file stack.c.

◆ is_stack_empty()

bool is_stack_empty ( t_gen  d)


Check stack empty

Parameters
d- Pointer to instance of stack
Returns
- true if empty

Definition at line 93 of file stack.c.

◆ is_stack_full()

bool is_stack_full ( t_gen  d)


Check stack full

Parameters
d- Pointer to instance of stack
Returns
- true if full

Definition at line 83 of file stack.c.

◆ stack_peek()

t_gen stack_peek ( t_gen  d,
int  idx 
)

Definition at line 298 of file stack.c.

◆ stack_pop_arr_down()

t_gen stack_pop_arr_down ( t_gen  d)


Pop an element from down growing ll stack

Parameters
d- Pointer to instance of stack
Returns
- Null if stack empty else data pointer

Definition at line 179 of file stack.c.

◆ stack_pop_arr_up()

t_gen stack_pop_arr_up ( t_gen  d)


Pop an element from up growing stack

Parameters
d- Pointer to instance of stack
Returns
- Null if stack empty else data pointer

Definition at line 135 of file stack.c.

◆ stack_pop_ll()

t_gen stack_pop_ll ( t_gen  d)


Pop an element from a link list based stack

Parameters
d- Pointer to instance of stack
Returns
- Null if stack empty else data pointer

Definition at line 225 of file stack.c.

◆ stack_print()

void stack_print ( t_gen  d)


print_stack_info

Parameters
d- Pointer to instance of stack
Returns
- NA

Definition at line 267 of file stack.c.

◆ stack_push_arr_down()

t_gen stack_push_arr_down ( t_gen  d,
t_gen  data 
)


Push an element into down growing stack

Parameters
d- Pointer to instance of stack
data- Pointer to the data to be pushed
Returns
- Null if stack Full else data pointer

Definition at line 158 of file stack.c.

◆ stack_push_arr_up()

t_gen stack_push_arr_up ( t_gen  d,
t_gen  data 
)


Push an element into up growing stack

Parameters
d- Pointer to instance of stack
data- Pointer to the data to be pushed
Returns
- Null is stack full else data pointer

Definition at line 114 of file stack.c.

◆ stack_push_ll()

t_gen stack_push_ll ( t_gen  d,
t_gen  data 
)


Push an element into a link list based stack

Parameters
d- Pointer to instance of stack
data- Pointer to the data to be pushed
Returns
- Null if stack Full else data pointer

Definition at line 202 of file stack.c.

◆ stack_size()

int stack_size ( t_gen  d)


get stack size

Parameters
d- Pointer to instance of stack
Returns
- size of stack

Definition at line 103 of file stack.c.

Variable Documentation

◆ stack_pop

Look Up function ptrs for poping to stack.

Definition at line 27 of file stack.c.

◆ stack_push

Look Up function ptrs for pushing to stack.

Definition at line 24 of file stack.c.