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 ?    3 Yes 0 No
Splurgeop
 
  Re: Program to Delete an element from a doubly linked list.
Answer
# 2
dsgfdagfdg
[op;iop
 
Is This Answer Correct ?    1 Yes 2 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 ?    1 Yes 0 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 ?    2 Yes 0 No
Viktor
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
Write a program that find and print how many odd numbers in a binary tree  1
What is the main difference between STRUCTURE and UNION?  3
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!  7
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. Wipro2
Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique. Microsoft3
Find the largest number in a binary tree Infosys4
program to find the roots of a quadratic equation  1
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. Microsoft4
write the function. if all the character in string B appear in string A, return true, otherwise return false. Google7
Finding a number which was log of base 2 NetApp1
How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com Deshaw8
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). Microsoft8
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) Microsoft4
Finding a number multiplication of 8 with out using arithmetic operator NetApp7
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. Microsoft2
program to Reverse a linked list Ness-Technologies3
Give a one-line C expression to test whether a number is a power of 2. Microsoft7
plz send me all data structure related programs  2
why java is platform independent? Wipro6
Program to find the largest sum of contiguous integers in the array. O(n)  5
 
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