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                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }  1
main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }  1
main() { signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); } } a. 0, 0 b. 0, 513 c. 512, 0 d. 0, -513 HCL1
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above HCL1
How will u find whether a linked list has a loop or not? Microsoft6
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
main() { unsigned char i=0; for(;i>=0;i++) ; printf("%d\n",i); }  1
void main() { int const * p=5; printf("%d",++(*p)); }  1
main() { char a[4]="HELL"; printf("%s",a); } Wipro1
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above HCL1
#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }  1
How to swap two variables, without using third variable ? HCL46
main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }  1
main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }  1
main() { int c=- -2; printf("c=%d",c); }  1
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  1
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. Microsoft15
What is "far" and "near" pointers in "c"...?  3
What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }  1
Write a program that find and print how many odd numbers in a binary tree  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