Page 46 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 46
Unit 2: Linked Lists
printf( “ Cannot allocate \n”); Notes
exit (0);
}
temp -> data = value;
temp -> right = p;
temp->left = NULL
p = temp ;
}
else
{
temp = p ;
i = 1;
while ( i < node_no )
{
i = i+1;
temp = temp-> right ;
}
temp1 = ( struct dnode * )malloc ( sizeof(struct dnode));
if ( temp == NULL )
{
printf(“Cannot allocate \n”);
exit(0);
}
temp1 -> data = value ;
temp1 -> right = temp -> right;
temp1 -> left = temp;
temp1->right->left = temp1;
temp1->left->right = temp1
}
return (p);
}
void main()
{
int n;
int x;
struct dnode *start = NULL ;
struct dnode *end = NULL;
printf(“Enter the nodes to be created \n”);
scanf(“%d”,&n);
while ( n- > 0 )
{
LOVELY PROFESSIONAL UNIVERSITY 41