Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int data;
- struct node* next;
- struct node* prev;
- };
- typedef struct node Node;
- typedef Node* pNode;
- pNode eliminazione_lista_bidirezionale(pNode lista, int elem)
- {
- pNode prec,curr;
- curr=lista;
- while(curr!=NULL && elem > curr->data)
- {
- curr=curr->next;
- }
- if(curr->data == elem)
- {
- if(curr->prev==NULL)///in testa
- {
- lista=curr->next;
- lista->prev=NULL;
- free(curr);
- }
- else if(curr->next==NULL)///in fondo
- {
- prec=curr->prev;
- prec->next=NULL;
- free(curr);
- }
- else ///in mezzo
- {
- prec=curr->prev;
- prec->next=curr->next;
- free(curr);
- }
- }
- return lista;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement