Custom C Library for data structure in C
[=> to store bunch of characters together in memory]
- Includes standard C library header files.
- #include <stdio.h> => input / output
- #include <stdlib.h> => dynamic memory allocation / de-allocation / re-allocation
- #include <string.h> => memory copy
- #include <stdarg.h> => variable number of arguments
- #include <stdbool.h> => true / false
- String has a length and a starting memory address
typedef struct STRING {
int length;
char* address;
} String;
Data Type | Varable Name | Usage |
---|---|---|
Integer | Length | to store the length value or the number of characters of the string |
Character Pointer | Address | to store the character type dynamic memory address of the string |
ERASE Macro (Pre-Processor) Function - Creating a univarsal alternative of freeing memory and assigning to NULL aka (void*)0 - This is irrespective of input datatype
#define ERASE(address) {\
free (*address);\
*address = NULL;\
}
- Create String
- Takes
- length of the string
- Character Array or Pointer
- Shows
- Error if Empty string is given
- Returns
- Null if length is Zero
- Pointer for String object
- Takes
- Delete String
- Takes
- Address of Pointer for String object
- Shows
- Error if Empty string is given
- Returns
- Nothing
- Takes
- Display String
- Takes
- Pointer for String object
- Shows
- Error if Empty string is given
- Prints only char sequence
- No new-line gets printed
- Returns
- Nothing
- Takes
- Display Raw String
- Takes
- Length
- Character Array or Pointer
- Shows
- Returns
- Nothing
- Takes
- Display String Properties
- Takes
- Pointer for String object
- Shows
- Returns
- Nothing
- Takes
- Char Array To Pointer
- Takes
- Length of Character Array
- Character Array
- Shows
- Nothing
- Returns
- Pointer for dynamic memory block
- Takes
- Concatenate Strings
- Takes
- Number of input string objects
- all the pointers for stgring objects (variable number of inputs)
- Shows
- Nothing
- Returns
- Pointer to the concatenated string object
- Takes
- Are Strings Equal
- Takes
- Pointer for first String object
- Pointer for second String object
- Shows
- Nothing
- Returns
- Boolean (True / False) value
- Takes
[=> to store any type of data in memory]
- Data has type, block size, and a starting memory address
typedef enum DATA_TYPE {
DT_Undefined
, DT_Binary
, DT_Character
, DT_Integer
, DT_String
, DT_Address
} Data_Type;
typedef struct DATA {
Data_Type type;
int size;
void* address;
} Data;
Data Type | Varable Name | Usage |
---|---|---|
Enumeration | Type | to store custom datatype for type casting memory block |
Integer | Size | to store the data block size |
Void Pointer | Address | to store starting address for the data block in memory |
- Create Data
- Takes
- datatype (enum) for data block
- Shows
- Nothing
- Returns
- Pointer for Data object
- Takes
- Duplicate Data
- Takes
- Pointer to Data object
- Shows
- Nothing
- Returns
- Pointer for a new Data object with same values
- Takes
- Forget Data
- Takes
- Address of the Pointer to Data object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Delete Data
- Takes
- Address of the Pointer to Data object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Data
- Takes
- Pointer to Data object
- Shows
- Formatted data according to datatype
- Returns
- Nothing
- Takes
- Display Data Properties
- Takes
- Pointer to Data object
- Shows
- Formatted data according to datatype
- Returns
- Nothing
- Takes
- Display Binary Data
- Takes
- Pointer to Data object
- Shows
- Data bytes in hexadecimal format value
- Returns
- Nothing
- Takes
[=> to store list of any data in memory]
- List has item count, item addresses
typedef struct LIST {
int item_count;
void** item_addresses;
} List;
Data Type | Varable Name | Usage |
---|---|---|
Integer | Item Count | to store number of items in the list |
Void Pointer of Pointers | Item Addresses | to store addresses of each data block in memory |
- Create List
- Takes
- Number of items
- Shows
- Nothing
- Returns
- Pointer to List object
- Takes
- Duplicate List
- Takes
- Pointer to List object
- Shows
- Nothing
- Returns
- New Pointer to copied List object
- Takes
- Forget List
- Takes
- Address of Pointer to List object
- Shows
- Nothing
- Returns
- New Pointer to copied List object
- Takes
- Delete List
- Takes
- Address of Pointer to List object
- Shows
- Nothing
- Returns
- New Pointer to copied List object
- Takes
- Add to List
- Takes
- Pointer to List object
- Pointer to Data
- Is data copy needed or not
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display List
- Takes
- Pointer to List object
- Shows
- Displays data for each item in the list
- Returns
- Nothing
- Takes
- Display List Addresses
- Takes
- Pointer to List object
- Shows
- Displays data address for each item in the list
- Returns
- Nothing
- Takes
[=> to store network node data in memory]
- Node has item count, item addresses
typedef enum NODE_TYPE {
N_Undefined
, N_LinkedList
, N_Stack
, N_Queue
, N_Tree
, N_Graph
} Node_Type;
typedef struct NODE {
Node_Type type;
String* name;
List* address_list;
Data* data;
} Node;
Data Type | Varable Name | Usage |
---|---|---|
Enumeration | Node Type | to store Network type that the node belongs to |
String Pointer | Name | to store name of the node |
List Pointer | Address List | to store addresses of other linked nodes |
Data Pointer | Data | to store any type of required data block |
- Create Node
- Takes
- Node type (enum) for Node block
- Shows
- Nothing
- Returns
- Pointer to Node object
- Takes
- Duplicate Node
- Takes
- Pointer to Node object
- Shows
- Nothing
- Returns
- New Pointer to copied Node object
- Takes
- Delete Node
- Takes
- Address of Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Set Node Name
- Takes
- Pointer to Node object
- Length of String
- Address to character sequence
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Node
- Takes
- Pointer to Node object
- Shows
- Name of the Node
- Returns
- Nothing
- Takes
- Display Node
- Takes
- Pointer to Node object
- Shows
- Type, address, name, address-list, stored data of the Node
- Returns
- Nothing
- Takes
[=> to store nodes as linked list format in memory]
- Linked List has name, size, first node, last node
typedef struct LINKED_LIST {
String* name;
int size;
Node* first_node;
Node* last_node;
} Linked_List;
- Create Linked List
- Takes
- Nothing
- Shows
- Nothing
- Returns
- Pointer to Linked List object
- Takes
- Delete Linked List
- Takes
- Address of Pointer to Linked List object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Linked List
- Takes
- Pointer to Linked List object
- Shows
- All the Nodes in the Linked List in linear fashion
- Returns
- Nothing
- Takes
- Attach Node at first
- Takes
- Pointer to Linked List object
- Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Attach Node at last
- Takes
- Pointer to Linked List object
- Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Detach Node from first
- Takes
- Pointer to Linked List object
- Shows
- Nothing
- Returns
- Pointer to copy of first Node object
- Takes
- Detach Node from last
- Takes
- Pointer to Linked List object
- Shows
- Nothing
- Returns
- Pointer to copy of last Node object
- Takes
[=> to store nodes as stack format in memory]
- Stack has name, size, first node, last node
typedef Linked_List Stack;
- Create Stack
- Takes
- Nothing
- Shows
- Nothing
- Returns
- Pointer to Stack object
- Takes
- Delete Stack
- Takes
- Pointer to Stack object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Stack
- Takes
- Pointer to Stack object
- Shows
- All the Nodes in the Stack
- Returns
- Nothing
- Takes
- Push
- Takes
- Pointer to Stack object
- Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Pop
- Takes
- Pointer to Stack object
- Shows
- Nothing
- Returns
- Pointer to copy of Node object
- Takes
[=> to store nodes as queue format in memory]
- Queue has name, size, first node, last node
typedef Linked_List Queue;
- Create Queue
- Takes
- Nothing
- Shows
- Nothing
- Returns
- Pointer to Queue object
- Takes
- Delete Queue
- Takes
- Pointer to Queue object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Queue
- Takes
- Pointer to Queue object
- Shows
- All Nodes in the Queue
- Returns
- Nothing
- Takes
- Enqueue
- Takes
- Pointer to Queue object
- Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Dequeue
- Takes
- Pointer to Queue object
- Shows
- Nothing
- Returns
- Pointer to copy of Node object
- Takes
[=> to store nodes as tree format in memory]
- Linked List has name, size, first node, last node
typedef struct TREE {
Node* root_node;
int node_count;
int breadth;
int depth;
} Tree;
- Create Tree
- Takes
- Nothing
- Shows
- Nothing
- Returns
- Pointer to Tree object
- Takes
- Duplicate Tree
- Takes
- Pointer to Tree object
- Shows
- Nothing
- Returns
- Pointer to copy of Tree object
- Takes
- Delete Tree
- Takes
- Address of Pointer to Tree object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Display Tree
- Takes
- Pointer to Tree object
- Shows
- All the Nodes in the Tree
- Returns
- Nothing
- Takes
- Set Root Node
- Takes
- Pointer to Tree object
- Pointer to Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Get Root Node
- Takes
- Pointer to Tree object
- Shows
- Nothing
- Returns
- Pointer to Root Node
- Takes
- Get N th Child Node
- Takes
- Pointer to Tree-Node object
- Index / Value of N
- Shows
- Nothing
- Returns
- Pointer to Tree-Node
- Takes
- Get Parent Node
- Takes
- Pointer to Tree-Node object
- Shows
- Nothing
- Returns
- Pointer to Parent Tree-Node object
- Takes
- Append Child Node
- Takes
- Pointer to Parent Tree-Node object
- Pointer to Child Tree-Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Push Tree-Node to Stack
- Takes
- Pointer to Tree-Stack object
- Pointer to Tree-Node object
- Shows
- Nothing
- Returns
- Nothing
- Takes
- Push Depth to Stack
- Takes
- Pointer to Tree-Stack object
- Child node count
- Shows
- Nothing
- Returns
- Nothing
- Takes
[=> to store nodes as graph format in memory]