Skip to content

Fundamental Data Structures in Computer Programming

License

Notifications You must be signed in to change notification settings

themdrizwanansari/Data_Structure_on_C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Data Structure

Custom C Library for data structure in C


Dependency Diagram =>

Image


Data Structures & Utility Functions =>

-: String.h :-

[=> to store bunch of characters together in memory]

Included Libraries

Image

  • 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

Data Structure

  • 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;\
	}

Utility Functions

  • Create String
    • Takes
      1. length of the string
      2. Character Array or Pointer
    • Shows
      • Error if Empty string is given
    • Returns
      • Null if length is Zero
      • Pointer for String object

  • Delete String
    • Takes
      1. Address of Pointer for String object
    • Shows
      • Error if Empty string is given
    • Returns
      • Nothing

  • Display String
    • Takes
      1. Pointer for String object
    • Shows
      • Error if Empty string is given
      • Prints only char sequence
      • No new-line gets printed
    • Returns
      • Nothing

  • Display Raw String
    • Takes
      1. Length
      2. Character Array or Pointer
    • Shows
    • Returns
      • Nothing

  • Display String Properties
    • Takes
      1. Pointer for String object
    • Shows
    • Returns
      • Nothing

  • Char Array To Pointer
    • Takes
      1. Length of Character Array
      2. Character Array
    • Shows
      • Nothing
    • Returns
      • Pointer for dynamic memory block

  • Concatenate Strings
    • Takes
      1. Number of input string objects
      2. all the pointers for stgring objects (variable number of inputs)
    • Shows
      • Nothing
    • Returns
      • Pointer to the concatenated string object

  • Are Strings Equal
    • Takes
      1. Pointer for first String object
      2. Pointer for second String object
    • Shows
      • Nothing
    • Returns
      • Boolean (True / False) value

-: Data.h :-

[=> to store any type of data in memory]

Included Libraries

Image

Data Structure

  • 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

Utility Functions

  • Create Data
    • Takes
      1. datatype (enum) for data block
    • Shows
      • Nothing
    • Returns
      • Pointer for Data object

  • Duplicate Data
    • Takes
      1. Pointer to Data object
    • Shows
      • Nothing
    • Returns
      • Pointer for a new Data object with same values

  • Forget Data
    • Takes
      1. Address of the Pointer to Data object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Delete Data
    • Takes
      1. Address of the Pointer to Data object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Data
    • Takes
      1. Pointer to Data object
    • Shows
      • Formatted data according to datatype
    • Returns
      • Nothing

  • Display Data Properties
    • Takes
      1. Pointer to Data object
    • Shows
      • Formatted data according to datatype
    • Returns
      • Nothing

  • Display Binary Data
    • Takes
      1. Pointer to Data object
    • Shows
      • Data bytes in hexadecimal format value
    • Returns
      • Nothing


-: List.h :-

[=> to store list of any data in memory]

Included Libraries

Image

Data Structure

  • 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

Utility Functions

  • Create List
    • Takes
      1. Number of items
    • Shows
      • Nothing
    • Returns
      • Pointer to List object

  • Duplicate List
    • Takes
      1. Pointer to List object
    • Shows
      • Nothing
    • Returns
      • New Pointer to copied List object

  • Forget List
    • Takes
      1. Address of Pointer to List object
    • Shows
      • Nothing
    • Returns
      • New Pointer to copied List object

  • Delete List
    • Takes
      1. Address of Pointer to List object
    • Shows
      • Nothing
    • Returns
      • New Pointer to copied List object

  • Add to List
    • Takes
      1. Pointer to List object
      2. Pointer to Data
      3. Is data copy needed or not
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display List
    • Takes
      1. Pointer to List object
    • Shows
      • Displays data for each item in the list
    • Returns
      • Nothing

  • Display List Addresses
    • Takes
      1. Pointer to List object
    • Shows
      • Displays data address for each item in the list
    • Returns
      • Nothing


-: Node.h :-

[=> to store network node data in memory]

Included Libraries

Image

Data Structure

  • 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

Utility Functions

  • Create Node
    • Takes
      1. Node type (enum) for Node block
    • Shows
      • Nothing
    • Returns
      • Pointer to Node object

  • Duplicate Node
    • Takes
      1. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • New Pointer to copied Node object

  • Delete Node
    • Takes
      1. Address of Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Set Node Name
    • Takes
      1. Pointer to Node object
      2. Length of String
      3. Address to character sequence
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Node
    • Takes
      1. Pointer to Node object
    • Shows
      • Name of the Node
    • Returns
      • Nothing

  • Display Node
    • Takes
      1. Pointer to Node object
    • Shows
      • Type, address, name, address-list, stored data of the Node
    • Returns
      • Nothing


-: Linked_List.h :-

[=> to store nodes as linked list format in memory]

Included Libraries

Image

Data Structure

  • 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;

Utility Functions

  • Create Linked List
    • Takes
      • Nothing
    • Shows
      • Nothing
    • Returns
      • Pointer to Linked List object

  • Delete Linked List
    • Takes
      1. Address of Pointer to Linked List object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Linked List
    • Takes
      1. Pointer to Linked List object
    • Shows
      • All the Nodes in the Linked List in linear fashion
    • Returns
      • Nothing

  • Attach Node at first
    • Takes
      1. Pointer to Linked List object
      2. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Attach Node at last
    • Takes
      1. Pointer to Linked List object
      2. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Detach Node from first
    • Takes
      1. Pointer to Linked List object
    • Shows
      • Nothing
    • Returns
      • Pointer to copy of first Node object

  • Detach Node from last
    • Takes
      1. Pointer to Linked List object
    • Shows
      • Nothing
    • Returns
      • Pointer to copy of last Node object


-: Stack.h :-

[=> to store nodes as stack format in memory]

Included Libraries

Image

Data Structure

  • Stack has name, size, first node, last node
typedef Linked_List Stack;

Utility Functions

  • Create Stack
    • Takes
      • Nothing
    • Shows
      • Nothing
    • Returns
      • Pointer to Stack object

  • Delete Stack
    • Takes
      1. Pointer to Stack object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Stack
    • Takes
      1. Pointer to Stack object
    • Shows
      • All the Nodes in the Stack
    • Returns
      • Nothing

  • Push
    • Takes
      1. Pointer to Stack object
      2. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Pop
    • Takes
      1. Pointer to Stack object
    • Shows
      • Nothing
    • Returns
      • Pointer to copy of Node object


-: Queue.h :-

[=> to store nodes as queue format in memory]

Included Libraries

Image

Data Structure

  • Queue has name, size, first node, last node
typedef Linked_List Queue;

Utility Functions

  • Create Queue
    • Takes
      • Nothing
    • Shows
      • Nothing
    • Returns
      • Pointer to Queue object

  • Delete Queue
    • Takes
      1. Pointer to Queue object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Queue
    • Takes
      1. Pointer to Queue object
    • Shows
      • All Nodes in the Queue
    • Returns
      • Nothing

  • Enqueue
    • Takes
      1. Pointer to Queue object
      2. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Dequeue
    • Takes
      1. Pointer to Queue object
    • Shows
      • Nothing
    • Returns
      • Pointer to copy of Node object


-: Tree.h :-

[=> to store nodes as tree format in memory]

Included Libraries

Image

Data Structure

  • Linked List has name, size, first node, last node
	typedef struct TREE {
		Node* root_node;
		int node_count;
		int breadth;
		int depth;
	} Tree;

Utility Functions

  • Create Tree
    • Takes
      • Nothing
    • Shows
      • Nothing
    • Returns
      • Pointer to Tree object

  • Duplicate Tree
    • Takes
      1. Pointer to Tree object
    • Shows
      • Nothing
    • Returns
      • Pointer to copy of Tree object

  • Delete Tree
    • Takes
      1. Address of Pointer to Tree object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Display Tree
    • Takes
      1. Pointer to Tree object
    • Shows
      • All the Nodes in the Tree
    • Returns
      • Nothing

  • Set Root Node
    • Takes
      1. Pointer to Tree object
      2. Pointer to Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Get Root Node
    • Takes
      1. Pointer to Tree object
    • Shows
      • Nothing
    • Returns
      • Pointer to Root Node

  • Get N th Child Node
    • Takes
      1. Pointer to Tree-Node object
      2. Index / Value of N
    • Shows
      • Nothing
    • Returns
      • Pointer to Tree-Node

  • Get Parent Node
    • Takes
      1. Pointer to Tree-Node object
    • Shows
      • Nothing
    • Returns
      • Pointer to Parent Tree-Node object

  • Append Child Node
    • Takes
      1. Pointer to Parent Tree-Node object
      2. Pointer to Child Tree-Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Push Tree-Node to Stack
    • Takes
      1. Pointer to Tree-Stack object
      2. Pointer to Tree-Node object
    • Shows
      • Nothing
    • Returns
      • Nothing

  • Push Depth to Stack
    • Takes
      1. Pointer to Tree-Stack object
      2. Child node count
    • Shows
      • Nothing
    • Returns
      • Nothing


-: Graph.h :-

[=> to store nodes as graph format in memory]

Included Libraries

Image

Data Structure

Utility Functions


About

Fundamental Data Structures in Computer Programming

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published