Program to Delete an element from a doubly linked list.

Answers were Sorted based on User's Feedback

Program to Delete an element from a doubly linked list. ..

// assumin all things are given function to delete
from beginning.....

int delete_from_beg()
{
int el;
{
printf("\n can't delete ");
return -1;
}
else
{
struct doubly *temp;
el=temp->info;
temp->next=NULL;
return el;
}

}

//delete from end

int delete_from_end()
{
int el;
{
printf("\n can't delete");
return -1;
}
else
{
struct doubly *temp;
while(temp->next!=NULL)
temp=temp->next;
el=temp->info;
else
temp->prev->next=NULL;
return el;
}
}

// delete from any position

int delete_at_pos(int item)
{
int el,flag=0;
struct doubly *temp;
{
printf("\n cant delete ");
return -1;
}
else
{
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
{
{
el=temp->info;
}
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

Program to Delete an element from a doubly linked list. ..

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

Program to Delete an element from a doubly linked list. ..

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

Program to Delete an element from a doubly linked list. ..

dsgfdagfdg
[op;iop

 Is This Answer Correct ? 7 Yes 21 No

More C Code Interview Questions

main() { int i = 3; for (;i++=0;) printf(“%d”,i); }

Write a C function to search a number in the given list of numbers. donot use printf and scanf

Is the following code legal? struct a { int x; struct a b; }

plz send me all data structure related programs

main() { extern int i; i=20; printf("%d",sizeof(i)); }

main() { show(); } void show() { printf("I'm the greatest"); }

int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }

Is the following code legal? typedef struct a { int x; aType *b; }aType

main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }

Categories