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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how are portions of a program disabled in demo versions?

874


What is wrong in this statement?

817


What’s the special use of UNIONS?

876


What is stack in c?

829


What are the uses of null pointers?

787


Can we add pointers together?

820


Explain how do you list a file’s date and time?

805


Why c is called free form language?

766


Explain a pre-processor and its advantages.

847


program for reversing a selected line word by word when multiple lines are given without using strrev

2175


Why is sprintf unsafe?

812


What is the use of ?: Operator?

895


How do I read the arrow keys? What about function keys?

847


What is structure in c explain with example?

864


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

878