C++ programming language part- 76 Inserting and Traversing a Node
Inserting and
Traversing a Node
Program 50_2
//linkedList
node.demo
class
node
{
char
name[10];
public:
node
*next;
void
accept()
{
cout<
cin>>name;
}
void
display()
{
cout<
}
};
class
list
{
node
*start;
public:
list()
{
start=NULL; } // Constructor, so start will carry NULL
void
add_node()
{
node
*fresh;
fresh=new
node;
fresh->accept();
fresh->next=start;
start=fresh;
}
void
traversal()
{
node
*temp;
for(temp=start;temp!=NULL;temp=temp->next)
temp->display();
}
};
main()
{
list
L;
L.add_node();
L.add_node();
L.add_node();
L.add_node();
L.traversal();
}