mirror of
https://github.com/Hizenberg469/C1-Linux_SYS_Prog-AS-.git
synced 2026-04-19 18:32:24 +03:00
Assignment about professionally Programming a library
This commit is contained in:
40
Assignment1/dll.c
Normal file
40
Assignment1/dll.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user