mirror of
https://github.com/Hizenberg469/C1-Linux_SYS_Prog-AS-.git
synced 2026-04-19 18:32:24 +03:00
static and dynamic lib
This commit is contained in:
60
Static_Dynamic_Lib/dll.c
Normal file
60
Static_Dynamic_Lib/dll.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* 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 <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
56
Static_Dynamic_Lib/dll.h
Normal file
56
Static_Dynamic_Lib/dll.h
Normal file
@@ -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);
|
||||
|
||||
BIN
Static_Dynamic_Lib/dll.o
Normal file
BIN
Static_Dynamic_Lib/dll.o
Normal file
Binary file not shown.
68
Static_Dynamic_Lib/dll_util.c
Normal file
68
Static_Dynamic_Lib/dll_util.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: dll_util.c
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 03/02/24 11:35:26 AM IST
|
||||
* Revision: none
|
||||
* Compiler: gcc
|
||||
*
|
||||
* Author: YOUR NAME (),
|
||||
* Organization:
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
#include "dll.h"
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
drain_dll (dll_t *dll){
|
||||
if( !dll || !dll->head ) return;
|
||||
|
||||
dll_node_t *tp = dll->head;
|
||||
dll_node_t * temp = dll->head;
|
||||
while( tp != NULL ){
|
||||
tp->right->left = NULL;
|
||||
temp = tp->right;
|
||||
tp->right = NULL;
|
||||
free(tp->data);
|
||||
free(tp);
|
||||
tp = temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
Static_Dynamic_Lib/dll_util.o
Normal file
BIN
Static_Dynamic_Lib/dll_util.o
Normal file
Binary file not shown.
BIN
Static_Dynamic_Lib/libdll.a
Normal file
BIN
Static_Dynamic_Lib/libdll.a
Normal file
Binary file not shown.
BIN
Static_Dynamic_Lib/libdll.so
Executable file
BIN
Static_Dynamic_Lib/libdll.so
Executable file
Binary file not shown.
Reference in New Issue
Block a user