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

Why does everyone say not to use scanf? What should I use instead?

0 Answers  


How to explain the final year project as a fresher please answer with sample project

0 Answers  


Find errors (1) m = ++a*5; (2) a = b ++ -c*2; (3)y = sqrt (1000);

5 Answers  


What is difference between array and structure in c?

0 Answers  


What is the general form of a C program?

0 Answers  






Differentiate b/w Modify and Update commands giving example.

1 Answers  


c programming of binary addition of two binary numbers

4 Answers  


whats the use of header file in c?

2 Answers  


FORMATTED INPUT/OUTPUT functions are a) scanf() and printf() b) gets() and puts() c) getchar() and putchar() d) all the above

0 Answers  


Discuss the function of conditional operator, size of operator and comma operator with examples.

0 Answers   TCS,


Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child

10 Answers   IBM, Infosys,


Can you mix old-style and new-style function syntax?

0 Answers  


Categories