Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
|
Dynamic Stack, just like Dynamic Array, is a stack data structure whose the length or capacity (maximum number of elements that can be stored) increases or decreases in real time based on the operations (like insertion or deletion) performed on it. More...
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
Data Structures | |
struct | DArrayStack |
to verify assumptions made by the program and print a diagnostic message if this assumption is false. More... | |
Typedefs | |
typedef struct DArrayStack | DArrayStack |
to verify assumptions made by the program and print a diagnostic message if this assumption is false. | |
Functions | |
DArrayStack * | create_stack (int cap) |
Create a Stack object. | |
DArrayStack * | double_array (DArrayStack *ptr, int cap) |
As this is stack implementation using dynamic array this function will expand the size of the stack by twice as soon as the stack is full. | |
DArrayStack * | shrink_array (DArrayStack *ptr, int cap) |
As this is stack implementation using dynamic array this function will shrink the size of stack by twice as soon as the stack's capacity and size has significant difference. | |
int | push (DArrayStack *ptr, int data) |
The push function pushes the element onto the stack. | |
int | pop (DArrayStack *ptr) |
The pop function to pop an element from the stack. | |
int | peek (DArrayStack *ptr) |
To retrieve or fetch the first element of the Stack or the element present at the top of the Stack. | |
int | show_capacity (DArrayStack *ptr) |
To display the current capacity of the stack. | |
int | isempty (DArrayStack *ptr) |
The function is used to check whether the stack is empty or not and return true or false accordingly. | |
int | stack_size (DArrayStack *ptr) |
Used to get the size of the Stack or the number of elements present in the Stack. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Dynamic Stack, just like Dynamic Array, is a stack data structure whose the length or capacity (maximum number of elements that can be stored) increases or decreases in real time based on the operations (like insertion or deletion) performed on it.
In this implementation, functions such as PUSH, POP, PEEK, show_capacity, isempty, and stack_size are coded to implement dynamic stack.
typedef struct DArrayStack DArrayStack |
to verify assumptions made by the program and print a diagnostic message if this assumption is false.
to provide a set of integer types with universally consistent definitions that are operating system-independent for IO operations for including functions involving memory allocation such as malloc
DArrayStack Structure of stack.
DArrayStack * create_stack | ( | int | cap | ) |
Create a Stack object.
cap | Capacity of stack |
DArrayStack * double_array | ( | DArrayStack * | ptr, |
int | cap | ||
) |
As this is stack implementation using dynamic array this function will expand the size of the stack by twice as soon as the stack is full.
ptr | Stack pointer |
cap | Capacity of stack |
int isempty | ( | DArrayStack * | ptr | ) |
int main | ( | void | ) |
int peek | ( | DArrayStack * | ptr | ) |
int pop | ( | DArrayStack * | ptr | ) |
The pop function to pop an element from the stack.
ptr | Stack pointer |
int push | ( | DArrayStack * | ptr, |
int | data | ||
) |
The push function pushes the element onto the stack.
ptr | Stack pointer |
data | Value to be pushed onto stack |
int show_capacity | ( | DArrayStack * | ptr | ) |
To display the current capacity of the stack.
ptr | Stack pointer |
DArrayStack * shrink_array | ( | DArrayStack * | ptr, |
int | cap | ||
) |
As this is stack implementation using dynamic array this function will shrink the size of stack by twice as soon as the stack's capacity and size has significant difference.
ptr | Stack pointer |
cap | Capacity of stack |
int stack_size | ( | DArrayStack * | ptr | ) |
|
static |
Self-test implementations.