ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
Program to Delete an element from a doubly linked list.
 Question Submitted By :: =-PKG-=
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Program to Delete an element from a doubly linked list.
Answer
# 1
// 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 ?    7 Yes 1 No
Splurgeop
 
  Re: Program to Delete an element from a doubly linked list.
Answer
# 2
dsgfdagfdg
[op;iop
 
Is This Answer Correct ?    2 Yes 5 No
Aggdhbsam
 
 
 
  Re: Program to Delete an element from a doubly linked list.
Answer
# 3
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 ?    4 Yes 2 No
Shruti
 
  Re: Program to Delete an element from a doubly linked list.
Answer
# 4
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 ?    9 Yes 1 No
Viktor
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } } a. 5, 4, 3, 2, 1 b. 0, 1, 2, 3, 4 c. 0, 1, 2, 4, 8 d. 1, 2, 4, 8, 16 HCL1
#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d----%d",*p,*q); }  1
main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?  1
union u { struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i; }u; main() { u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l); } a. 4, 4, 0 b. 0, 0, 0 c. 100, 4, 0 d. 40, 4, 0 HCL1
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }  1
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.  3
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }  1
int i=10; main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); }  1
void main() { static int i=5; if(--i){ main(); printf("%d ",i); } }  1
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }  1
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }  1
Program to Delete an element from a doubly linked list. Infosys4
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }  1
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }  1
main() { 41printf("%p",main); }8  1
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }  1
What are the files which are automatically opened when a C file is executed?  1
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped IBM1
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }  1
main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com