Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program to implement a singly linked list of integer values (MyLinkedList) with the following operations: 1. void add(int x) - add a

Write a Java program to implement a singly linked list of integer values (MyLinkedList) with the following operations:

1. void add(int x) - add a node with value x at the tail of a list.

2. void traverse() - traverse from head to tail and display info of all nodes in the list.

3. void delete(int x) - delete the first node whose info is equal to x.

4. Node search(int x) - search and return the reference to the first node having info x.

5. int count() - count and return number of nodes in the list.

6. void sort() - sort the list by ascending order of info.

7. int max() - find and return the maximum value in the list.

8. int sum() - return the sum of all values in the list.

9. int avg() - return the average of all values in the list. T

he main() functions should be:

MyLinkedList a = new MyLinkedList();

a.add(5);

a.add(7);

a.add(2);

a.add(8);

a.add(3);

a.traverse(); // 5, 7, 2, 8, 3

a.search(1); // Not found

a.search(8); // Found at the 3-th position.

a.max(); // 8;

a.sum(); // sum: 25

a. avg(); // avg: 5

a.count(); // count: 5

a.sort(); // 2, 3, 5, 7, 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

b. "(2.00 Answered: 1 week ago

Answered: 1 week ago