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 |
main() { extern i; printf("%d\n",i); { int i=20; printf("%d\n",i); } }
C statement to copy a string without using loop and library function..
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.
main() { int i=-1; +i; printf("i = %d, +i = %d \n",i,+i); }
main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }
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
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.
write a program to count the number the same (letter/character foreg: 's') in a given sentence.
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); }
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.
Develop a routine to reflect an object about an arbitrarily selected plane