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. ..

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

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

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

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

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

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

Answer / aggdhbsam

dsgfdagfdg
[op;iop

Is This Answer Correct ?    7 Yes 21 No

Post New Answer

More C Code Interview Questions

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

1 Answers  


C statement to copy a string without using loop and library function..

2 Answers   Persistent, TCS,


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

2 Answers   Wipro,


main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }

1 Answers  


main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }

1 Answers  






main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. ā€“3, -1, 1, 3, 5

2 Answers   HCL,


There is a lucky draw held every day. if there is a winning number eg 1876,then all possible numbers like 1867,1687,1768 etc are the numbers that match irrespective of the position of the digit. Thus all these numbers qualify fr the lucky draw prize Assume there is no zero digit in any numbers. write a program to show all the possible winning numbers if a "winning number"is passed as an arguments to the function.

1 Answers   Nagarro,


write a program to count the number the same (letter/character foreg: 's') in a given sentence.

2 Answers  


how can u draw a rectangle in C

53 Answers   Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,


void main() { static int i=i++, j=j++, k=k++; printf(ā€œi = %d j = %d k = %dā€, i, j, k); }

3 Answers  


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.

1 Answers  


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


Categories