commit 6fc2b0cef0401a8324f27908d4f9ba8f95c45d18 Author: Hizenberg Date: Fri Feb 2 22:57:09 2024 +0530 More Organised diff --git a/Header_files/A.h b/Header_files/A.h new file mode 100644 index 0000000..affdc2c --- /dev/null +++ b/Header_files/A.h @@ -0,0 +1,21 @@ +/* + * ===================================================================================== + * + * Filename: A.h + * + * Description: + * + * Version: 1.0 + * Created: 02/02/24 10:15:59 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + + +#define max(a,b) ( a > b ? a : b ) +int sum(int a,int b); diff --git a/Header_files/B.h b/Header_files/B.h new file mode 100644 index 0000000..9f609db --- /dev/null +++ b/Header_files/B.h @@ -0,0 +1,21 @@ +/* + * ===================================================================================== + * + * Filename: B.h + * + * Description: + * + * Version: 1.0 + * Created: 02/02/24 10:18:06 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "A.h" +#define min(a,b) ( a > b ? b : a ) +int multiply ( int a , int b ); diff --git a/Header_files/app.c b/Header_files/app.c new file mode 100644 index 0000000..4fb05c0 --- /dev/null +++ b/Header_files/app.c @@ -0,0 +1,31 @@ +/* + * ===================================================================================== + * + * Filename: app.c + * + * Description: + * + * Version: 1.0 + * Created: 02/02/24 10:43:11 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "B.h" +#define square(x) ( x*x ) + + +int foo(int b); +int foo(int b){ + +} + +int main(){ + int a = square(15); + return 0; +} diff --git a/Header_files/app.i b/Header_files/app.i new file mode 100644 index 0000000..a4a8881 --- /dev/null +++ b/Header_files/app.i @@ -0,0 +1,28 @@ +# 0 "app.c" +# 0 "" +# 0 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 0 "" 2 +# 1 "app.c" +# 19 "app.c" +# 1 "B.h" 1 +# 19 "B.h" +# 1 "A.h" 1 +# 21 "A.h" +int sum(int a,int b); +# 20 "B.h" 2 + +int multiply ( int a , int b ); +# 20 "app.c" 2 + + + +int foo(int b); +int foo(int b){ + +} + +int main(){ + int a = ( 15*15 ); + return 0; +} diff --git a/Quick_Compilation/application.c b/Quick_Compilation/application.c new file mode 100644 index 0000000..a099815 --- /dev/null +++ b/Quick_Compilation/application.c @@ -0,0 +1,82 @@ +/* + * ===================================================================================== + * + * Filename: application.c + * + * Description: + * + * Version: 1.0 + * Created: 28/01/24 07:56:36 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + +#include "dll.h" +#include +#include +#include + +/*Application specific data structures*/ +typedef struct person_{ + + char name[32]; + int age; + int weight; +} person_t; + +static void +print_person_details(person_t *person){ + + printf("Name = %s\n", person->name); + printf("Age = %d\n", person->age); + printf("weight = %d\n", person->weight); +} + +static void +print_person_db(dll_t *person_db) { + + if(!person_db || !person_db->head) return; + + dll_node_t *head = person_db->head; + person_t *data = NULL; + + while(head){ + data = head->data; + print_person_details(data); + head = head->right; + } +} + +int +main(int argc, char **argv){ + + person_t *person1 = calloc(1, sizeof(person_t)); + strncpy(person1->name, "Abhishek", strlen("Abhishek")); + person1->age = 31; + person1->weight = 75; + person_t *person2 = calloc(1, sizeof(person_t)); + strncpy(person2->name, "Joseph", strlen("Joseph")); + person2->age = 41; + person2->weight = 70; + person_t *person3 = calloc(1, sizeof(person_t)); + strncpy(person3->name, "Jack", strlen("Jack")); + person3->age = 29; + person3->weight = 55; + + /*Create a new Linked List*/ + + dll_t *person_db = get_new_dll(); + add_data_to_dll(person_db, person1); + add_data_to_dll(person_db, person2); + add_data_to_dll(person_db, person3); + + print_person_db(person_db); + + return 0; +} + diff --git a/Quick_Compilation/dll.c b/Quick_Compilation/dll.c new file mode 100644 index 0000000..62c1ebd --- /dev/null +++ b/Quick_Compilation/dll.c @@ -0,0 +1,90 @@ +/* + * ===================================================================================== + * + * Filename: dll.c + * + * Description: + * + * Version: 1.0 + * Created: 28/01/24 07:59:34 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + + + +#include "dll.h" +#include +#include + +/* Public Function Implementation to create and return + * new empty doubly linked list*/ + +dll_t * +get_new_dll(){ + + dll_t *dll = calloc(1, sizeof(dll_t)); + dll->head = NULL; + return dll; +} + +/* Public Function Implementation to add a new application + * * data to DLL */ +int +add_data_to_dll (dll_t *dll, void *app_data){ + + if(!dll || !app_data) return -1; + + dll_node_t *dll_new_node = calloc(1, sizeof(dll_node_t)); + dll_new_node->left = NULL; + dll_new_node->right = NULL; + dll_new_node->data = app_data; + + /*Now add this to the front of DLL*/ + if(!dll->head){ + dll->head = dll_new_node; + return 0; + } + + dll_node_t *first_node = dll->head; + dll_new_node->right = first_node; + first_node->left = dll_new_node; + dll->head = dll_new_node; + return 0; +} + +int +remove_data_from_dll_by_data_ptr (dll_t *dll, void *data ){ + + if( !dll || !dll->head || !data ) return -1; + + /* Searching for data linearly and deleting the data*/ + dll_node_t *tp; + dll_node_t *temp = dll->head; + while( !temp ){ + if( *((int *)temp->data) == *((int *)data) ){ + tp = temp->left; + tp->right = temp->right; + free(temp); + return 0; + } + temp = temp->right; + } + + return -1; +} + +int +is_dll_empty(dll_t *dll){ + + if( !dll || !dll->head ) return 0; + + return -1; +} + + diff --git a/Quick_Compilation/dll.h b/Quick_Compilation/dll.h new file mode 100644 index 0000000..703509e --- /dev/null +++ b/Quick_Compilation/dll.h @@ -0,0 +1,56 @@ +/* + * ===================================================================================== + * + * Filename: dll.h + * + * Description: + * + * Version: 1.0 + * Created: 28/01/24 07:58:51 PM IST + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ + + +/*Header file for Doubly Linked List*/ + +typedef struct dll_node_{ + + void *data; + struct dll_node_ *left; + struct dll_node_ *right; +} dll_node_t; + +typedef struct dll_{ + dll_node_t *head; +} dll_t; + + +/* Public Function declaration to create and return + * a new empty doubly linked list*/ +dll_t * +get_new_dll(); + +/* Public Function declaration to add the application + * data to DLL*/ +int +add_data_to_dll(dll_t *dll, void *app_data); + + +/*More functions*/ +int /*return 0 on success and -1 on failure*/ +remove_data_from_dll_by_data_ptr (dll_t *dll, void *data); + +/*return 0 if empty, -1 if not empty*/ +int +is_dll_empty (dll_t *dll); + +/* delete all nodes from a dll, but do not free appln data*/ +void +drain_dll (dll_t *dll); +