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

What is non linear data structure in c?

796


What is output redirection?

918


What is memory leak in c?

855


What is the collection of communication lines and routers called?

884


How can I open files mentioned on the command line, and parse option flags?

838


WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER

1648


Explain how do you override a defined macro?

829


number of times a digit is present in a number

1804


What is table lookup in c?

858


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

875


Explain what is gets() function?

831


is it possible to create your own header files?

856


How do I get a null pointer in my programs?

862


Is c easy to learn?

758


What do the functions atoi(), itoa() and gcvt() do?

935