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
Explain how are portions of a program disabled in demo versions?
What is wrong in this statement?
What’s the special use of UNIONS?
What is stack in c?
What are the uses of null pointers?
Can we add pointers together?
Explain how do you list a file’s date and time?
Why c is called free form language?
Explain a pre-processor and its advantages.
program for reversing a selected line word by word when multiple lines are given without using strrev
Why is sprintf unsafe?
What is the use of ?: Operator?
How do I read the arrow keys? What about function keys?
What is structure in c explain with example?
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