// INSERTING SOME NODES IN THE DOUBLY LINKED LIST
# include<iostream.h>
# include <stdio.h>
# include <alloc.h>
# include<conio.h>
struct Double
{
char info[20];
struct Double *next;
struct Double *previous;
};
class D_insert
{
public: int i;
Double start, *new1;
public:
void Doubly_insertion_First (Double *);
void Doubly_Create_First (Double *);
void Display (Double *);
};
// Function create a list of five nodes
void D_insert :: Doubly_Create_First (Double *node)
{
int i = 0;
start.next = NULL; // Empty list
start.previous = NULL;
node = &start; // Point to the start of the list
cout<<"\n Input choice n for break: ";
char ch = getche();
while (ch != 'n')
{
node->next = (Double *) malloc(sizeof(Double ));
node->next->previous = node;
node = node->next;
cout<<"\n Input the value for :"<<i+1<<" : ";
cin>>node->info;
node->next = NULL;
i++;
cout<<"\n Input choice n for break: ";
ch = getche();
}
}
void D_insert :: Doubly_insertion_First (Double *node)
{
node = start.next;
new1 = (Double *) malloc(sizeof(Double ));
cout<<"\n Input the first node value; ";
cin>>new1->info;
cout<<"\n new1 address:"<<new1;
cout<<"\n Node address:"<<node;
new1->next = node;
cout<<"\n New1 next address:"<<new1->next;
cout<<"\n Node previous address:"<<node->previous;
new1->previous = node->previous;
node->previous->next = new1;
cout<<"\n node->previous.next:"<<node->previous->next;
cout<<"\n Node previous address:"<<node->previous;
cout<<"\n Node next address:"<<node->next;
cout<<"\n new1 address:"<<new1;
node->previous = new1;
cout<<"\n node->previous:"<<node->previous;
}
// Display the list
void D_insert :: Display (Double *node)
{
node = start.next;
while (node)
{
cout<<"\n "<<node;
cout<<" " <<node->info;
node = node->next;
}
}
void main()
{
D_insert D_ins;
Double *node = (Double *) malloc(sizeof(Double));
D_ins.Doubly_Create_First (node);
cout<<"\n Created list is as follows\n";
D_ins.Display(node);
D_ins.Doubly_insertion_First (node);
cout<<"\n List after insertion of first node \n";
D_ins.Display (node);
}
# include<iostream.h>
# include <stdio.h>
# include <alloc.h>
# include<conio.h>
struct Double
{
char info[20];
struct Double *next;
struct Double *previous;
};
class D_insert
{
public: int i;
Double start, *new1;
public:
void Doubly_insertion_First (Double *);
void Doubly_Create_First (Double *);
void Display (Double *);
};
// Function create a list of five nodes
void D_insert :: Doubly_Create_First (Double *node)
{
int i = 0;
start.next = NULL; // Empty list
start.previous = NULL;
node = &start; // Point to the start of the list
cout<<"\n Input choice n for break: ";
char ch = getche();
while (ch != 'n')
{
node->next = (Double *) malloc(sizeof(Double ));
node->next->previous = node;
node = node->next;
cout<<"\n Input the value for :"<<i+1<<" : ";
cin>>node->info;
node->next = NULL;
i++;
cout<<"\n Input choice n for break: ";
ch = getche();
}
}
void D_insert :: Doubly_insertion_First (Double *node)
{
node = start.next;
new1 = (Double *) malloc(sizeof(Double ));
cout<<"\n Input the first node value; ";
cin>>new1->info;
cout<<"\n new1 address:"<<new1;
cout<<"\n Node address:"<<node;
new1->next = node;
cout<<"\n New1 next address:"<<new1->next;
cout<<"\n Node previous address:"<<node->previous;
new1->previous = node->previous;
node->previous->next = new1;
cout<<"\n node->previous.next:"<<node->previous->next;
cout<<"\n Node previous address:"<<node->previous;
cout<<"\n Node next address:"<<node->next;
cout<<"\n new1 address:"<<new1;
node->previous = new1;
cout<<"\n node->previous:"<<node->previous;
}
// Display the list
void D_insert :: Display (Double *node)
{
node = start.next;
while (node)
{
cout<<"\n "<<node;
cout<<" " <<node->info;
node = node->next;
}
}
void main()
{
D_insert D_ins;
Double *node = (Double *) malloc(sizeof(Double));
D_ins.Doubly_Create_First (node);
cout<<"\n Created list is as follows\n";
D_ins.Display(node);
D_ins.Doubly_insertion_First (node);
cout<<"\n List after insertion of first node \n";
D_ins.Display (node);
}
No comments:
Post a Comment