Program to Delete an element from a doubly linked list.
Answers were Sorted based on User's Feedback
Answer / splurgeop
// assumin all things are given function to delete
from beginning.....
int delete_from_beg()
{
int el;
if(head==NULL)
{
printf("\n can't delete ");
return -1;
}
else
{
struct doubly *temp;
temp=head;
el=temp->info;
head=temp->next;
temp->next=NULL;
head->prev=NULL;
return el;
}
}
//delete from end
int delete_from_end()
{
int el;
if(head==NULL)
{
printf("\n can't delete");
return -1;
}
else
{
struct doubly *temp;
temp=head;
while(temp->next!=NULL)
temp=temp->next;
el=temp->info;
if(temp==head)
head=NULL;
else
temp->prev->next=NULL;
return el;
}
}
// delete from any position
int delete_at_pos(int item)
{
int el,flag=0;
struct doubly *temp;
if(head==NULL)
{
printf("\n cant delete ");
return -1;
}
else
{
temp=head;
while(item>1)
{
item--;
temp=temp->next;
if(temp==NULL&& item>=1)
{
flag=1;
break;
}
}
if(flag==1)
{
el=-1;
printf("\n cant delete at the specified
location");
}
else
{
if(temp==head)
{
el=temp->info;
head=temp->next;
}
else
{
struct doubly *t;
t=temp;
el=temp->info;
temp->prev->next=t->next;
temp->next->prev=t->prev;
}
}
}
return el;
}
// where doubly is structure
struct doubly
{
int data;
struct doubly *prev,*next;
};
Is This Answer Correct ? | 34 Yes | 9 No |
Answer / viktor
typedef int info_t;
typedef struct element
{
info_t info;
struct element *next;
struct element *prev;
}node;
typedef node* nodep;
Function to delete a node:
void del_node(nodep p)
{
(p->prev)->next=p->next;
(p->next)->prev=p->prev;
free(p);
}
Is This Answer Correct ? | 20 Yes | 9 No |
Answer / shruti
to delete an element.
enter the position of the element to be deleted.
-> pos.
structure of node is
struct node
{
int data;
struct node *prev , *next;
}
//home is the starting pointer of hte list.
struct node * delete(struct node *home , int pos)
{
temp = home;
if(pos == 1)
{
temp = home;
home = home -> next;
free(temp);
}
temp = home;
p = home;
for(i = 0 ; i < pos ; i++)
{
p = p -> next;
}
temp = p -> next;
temp1 = temp -> next;
p -> next = temp1;
temp1 -> prev = p
free(temp);
}
return home;
}
Is This Answer Correct ? | 9 Yes | 5 No |
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }
void main() { int i=5; printf("%d",i+++++i); }
Is the following code legal? typedef struct a { int x; aType *b; }aType
how can i search an element in an array
2 Answers CTS, Microsoft, ViPrak,
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);
plz send me all data structure related programs