writw a program to insert an element in the begning of a
doubly linked list



writw a program to insert an element in the begning of a doubly linked list..

Answer / mani

#include<stdio.h>

typedef struct node {
int data;
struct node *leftlink;
struct node *rightlink;
}node;

node *start=NULL;
node *tail=NULL;

void add_begin(node *);
main()
{

.......
.......

add_begin(start);

.......
.......
}

void add_begin(node *temp)
{
node *new_node=NULL;
int idata;
printf("enter the data part value: ");
scanf("%d",&idata);

if(start==NULL && tail==NULL )
{
new_node=(node *)malloc(sizeof(node));
new_node->data=idata;
new_node->leftlink=NULL;
new_node->rightlink=NULL;
start=new_node;
tail=new_node;
}
else
{
new_node=(node *)malloc(sizeof(node));
new_node->data=idata;
temp->leftlink=new_node;
new_node->rightlink=temp;
new_node->leftlink=NULL;
start=newnode;
}
}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Interview Questions

can anyone suggest some site name..where i can get some good data structure puzzles???

0 Answers  


swap 2 numbers without using third variable?

0 Answers   IBS,


What is #line used for?

0 Answers  


Explain what is operator promotion?

0 Answers  


What are the difference between a free-standing and a hosted environment?

0 Answers   Infogain,






any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

0 Answers  


write a c program for greatest of three numbers without using if statment

4 Answers   IBM,


int j =15,i; for (i=1; 1<5; ++i) {printf ("%d%d ",j,i); j = j-3; }

2 Answers  


what is pointer?

13 Answers   HCL, TCS,


How can I manipulate individual bits?

0 Answers  


Explain following declaration int *P(void); and int (*p)(char *a);

3 Answers  


How to add two numbers with using function?

2 Answers   Miracle Solutions,


Categories