A friend class has access to all private members of another class. In this exercise, you are going to practice friend classes by re-implementing the linked list structure.
Node that has two private data members: data and next.Linked_list that has two private data members: head and tail and four public member functions: output(), add_node(int), reverse(), as well as a default constructor.Node, declare friend class Linked_list;Linked_list, in which the add_node(int)function adds a node at the tail.main().
int main(){
Linked_list my_list;
int data, input_size;
/* when you add a node, you add it at the tail */
cin >> input_size;
for(int i=0; i < input_size; ++i) {
cin >> data;
my_list.add_node(data);
}
my_list.output();
my_list.reverse();
my_list.output();
return 0;
}
DO NOT CHANGE MAIN, otherwise your work will not be regarded as correct even if you pass all test cases. You may get PENALTY POINTS for changing main().
5
1 2 3 4 5
1 2 3 4 5
5 4 3 2 1
9
3 98 34 9 1 4 8 8 54
3 98 34 9 1 4 8 8 54
54 8 8 4 1 9 34 98 3