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

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

472


List the difference between a 'copy constructor' and a 'assignment operator' in C?

639


what are enumerations in C

725


in iso what are the common technological language?

1638


What is maximum size of array in c?

585






What is 1d array in c?

602


What is the difference between int main and void main?

576


What is static function in c?

636


Why static is used in c?

624


How to draw the flowchart for structure programs?

8763


Why is this loop always executing once?

618


Is c language still used?

538


List the difference between a "copy constructor" and a "assignment operator"?

586


How many types of sorting are there in c?

614


Here is a good puzzle: how do you write a program which produces its own source code as output?

600