Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

What is #define?

0 Answers  


where do we use volatile keyword?

1 Answers  


write an algorithm to get a sentence and reverse it in the following format: input : I am here opuput: Here Am I note: first letter of every word is capiatlised

3 Answers  


when will be evaluated as true/ if(x==x==x) a) x=1; b) x=0; c) x=-1; d) none

7 Answers   HCL,


What are run-time errors?

0 Answers  






What is the explanation for cyclic nature of data types in c?

0 Answers  


biggest of two no's with out using if condition statement

8 Answers  


What is the scope of global variable in c?

0 Answers  


What functions are used for dynamic memory allocation in c language?

0 Answers  


can we write a c program with out using main

3 Answers  


What are pointers? What are different types of pointers?

0 Answers   Fidelity,


How to draw the flowchart for structure programs?

0 Answers  






Categories