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

can any one provide me the notes of data structure for ignou cs-62 paper

1678


Explain how can I prevent another program from modifying part of a file that I am modifying?

614


What does stand for?

572


What is the return type of sizeof?

566


we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above

605






How can I read/write structures from/to data files?

524


Is sizeof a keyword in c?

554


How macro execution is faster than function ?

637


What does int main () mean?

522


What is the use of #include in c?

554


ATM machine and railway reservation class/object diagram

4783


1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures

2713


What is && in c programming?

646


How can I access an I o board directly?

598


Where local variables are stored in c?

532