From 6d6a749fa0ed68e5cdf1868c80083c0c65dfaa7e Mon Sep 17 00:00:00 2001 From: 99omniaashraf Date: Wed, 24 Jan 2024 09:09:47 -0800 Subject: [PATCH] Double linked list --- .../4-delete_dnodeint/delete_dnodeint | Bin 0 -> 17216 bytes .../delete_dnodeint_at_index.c | 53 ++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100755 0x00-challenge/4-delete_dnodeint/delete_dnodeint create mode 100644 0x00-challenge/4-delete_dnodeint/delete_dnodeint_at_index.c diff --git a/0x00-challenge/4-delete_dnodeint/delete_dnodeint b/0x00-challenge/4-delete_dnodeint/delete_dnodeint new file mode 100755 index 0000000000000000000000000000000000000000..1844945fc657ae0156b792f624fa3b71fc23acaf GIT binary patch literal 17216 zcmeHOeQ;FO6~CJg2w$7U0wO4^h#e5JBnXJw=x)furV|8XQgsSEHhCMeb+emp-fEy? zqp2S|F_x*F7H6Cm+nMT&RFMP{@W%Q!Gjr`SPFfYOMfu?pMYx%ZyU+n3GQ zb~@8P+&lB$x#xF2?!D*Uci+43z5Byp{puo@OK>U{*9qc|c@*N;g6?Z|2E;E`iYYkH z6?4Qm@Ffyca=#*ws&u3%mzHU~7?kX0QYH_*SiyoR*N`aLjhV)42~*t;vMVK#=AHDc z)@RD{YFTSO?m6J-Njz%MmVXdV8N8jyAgI2 zmwz{LH#g|=#_ESQ9e<`eykbc#+Pq@fl9*W$i^fx36rD8T$|_L3s0&C$E2kyn;ObYcQ!l4Yyy112&weT(TLm z;izaf4cl-U*PM21oP1EbIqk9Gd~K1e--h!XLHO%7T+a6dBE4n9xy?#aI2R&Nh(I9% zg$NWPP>4Vw0$;BPd|W=~pP`;pWue~Eqj;tc-P>;!W!?()>@V9V1Cd$24e*)F^P%)mXz%Ik zLwkpdL$23Cht6Bm;NV{Epe%E&Ro0X3DSqA6Bo?VfO`)FZX3B=r?^}~Yz16K?29BQ3 zWClzG>$TF2;9VPGn=PO02k(H8GEJ~UXL`&~Z^`8gq@Un$Re$I}a0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=!_q?|L5AiM(gqVoN1TMo@|`)dkh%G zg#F_tt&*nBCwgc9KkBgeYCEQzwL2yb_u_GfeYaL%%KBs3?{?Vp`i$v%Hq?~;F@4@) ze@qLQmQu&r65BEK3NrTi@p_LbzZYVCXZ-%4?YaMjS8Hm@?};=j#|r0(zKMg%XZwr2 zV33%aip`##<-ZGw-M-taRGB_NLR;eT!_fQ4(3(w8JK6OU@Ar1c literal 0 HcmV?d00001 diff --git a/0x00-challenge/4-delete_dnodeint/delete_dnodeint_at_index.c b/0x00-challenge/4-delete_dnodeint/delete_dnodeint_at_index.c new file mode 100644 index 0000000..aea4e45 --- /dev/null +++ b/0x00-challenge/4-delete_dnodeint/delete_dnodeint_at_index.c @@ -0,0 +1,53 @@ +#include "lists.h" +#include + +/** + * delete_dnodeint_at_index - Delete a node at a specific index from a list + * + * @head: A pointer to the first element of a list + * @index: The index of the node to delete + * + * Return: 1 on success, -1 on failure + */ +int delete_dnodeint_at_index(dlistint_t **head, unsigned int index) +{ + dlistint_t *saved_head; + dlistint_t *tmp; + unsigned int p; + + if (*head == NULL) + { + return (-1); + } + saved_head = *head; + p = 0; + while (p < index && *head != NULL) + { + *head = (*head)->next; + p++; + } + if (p != index) + { + *head = saved_head; + return (-1); + } + if (0 == index) + { + tmp = (*head)->next; + free(*head); + *head = tmp; + if (tmp != NULL) + { + tmp->prev = NULL; + } + } + else + { + (*head)->prev->next = (*head)->next; + free(*head); + if ((*head)->next) + (*head)->next->prev = (*head)->prev; + *head = saved_head; + } + return (1); +}