The following is a partial definition of a LinkList class that represents a linked list of integer values. Three member

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

The following is a partial definition of a LinkList class that represents a linked list of integer values. Three member

Post by answerhappygod »

The following is a partial definition of
a LinkList class that represents a linked list of integer
values. Three member functions are missing their definitions:
struct
Node
{
int data;
Node*
next;
};
class
LinkList
{
private:
Node*
first;
public:
LinkList() {first =
NULL;}
void add(int d);
int
pop();
void
display();
};
When the complete class is combined with the
following main, compiled, and run, an example of the output
generated is shown on the next page.
int main()
{
LinkList li;
int sel=1,n;
while (sel != 4)
{
cout << "\nMake a
selection:\n";
cout << "1 - Add a value to
the end of the list\n";
cout << "2 - Pop the front
value off the list\n";
cout << "3 - Display the
list\n";
cout << "4 - Exit the
program\n";
cout << "=> ";
cin >> sel;
switch (sel)
{
case 1:
cout << "\nEnter data value to add: ";
cin >> n;
li.add(n);
break;
case 2:
cout << "\nPopped front list value: " << li.pop()
<< endl;
break;
case 3:
li.display();
cout << endl;
break;
case 4:
cout << "\nExiting the program.\n";
break;
default:
cout << "\nInvalid selection - try again.\n";
break;
}
}
return 0;
}
Sample output (user input is shown in bold):
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 1
Enter data value to add: 222
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 1
Enter data value to add: 555
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 3
222
555
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 2
Popped front list value: 222
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 3
555
Make a selection:
1 - Add a value to the end of the list
2 - Pop the front value off the list
3 - Display the list
4 - Exit the program
=> 4
Write the definitions of the undefined member functions
on the next page. DON’T write the full program.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply