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

void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }

1 Answers  


Write a program to model an exploding firecracker in the xy plane using a particle system

0 Answers   HCL,


Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.

3 Answers   Wipro,


main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }

2 Answers   Wipro,


Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

1 Answers  






Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }

1 Answers  


Write, efficient code for extracting unique elements from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) -> (1, 3, 5, 9).

12 Answers   TCS, Intel, Microsoft,


main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }

1 Answers  


main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }

1 Answers  


programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h

1 Answers  






Categories