Home / Expert Answers / Computer Science / java-programming-question-1-write-a-java-program-to-implement-a-singly-linked-list-of-integer-val-pa660

(Solved): java programming Question 1. Write a Java program to implement a singly linked list of integer val ...



Question 1. Write a Java program to implement a singly linked list of integer values with the following operations:
1. void a

java programming

Question 1. Write a Java program to implement a singly linked list of integer values with the following operations: 1. void addToHead(int x) - add a node with value x at the head of a list. 2. void add To Tail(int x) - add a node with value x at the tail of a list. 3. void addAfter (Node p, int x) - add a node with value x after the node p. 4. void traverse() - traverse from head to tail and dislay info of all nodes in the list. 5. int deleteFromHead()) - delete the head and return its info. 6. int deleteFrom Tail() - delete the tail and return its info. 7. int deleteAter(Node p) - delete the node after the node p and return its info. 8. void dele(int x) - delele the first node whose info is equal to x. 9. Node search(int x) - search and return the reference to the first node having info x. 10. int count() - count and return number of nodes in the list. 11. void dele(int i) - delete an i-th node on the list. Besure that such a node exists. 12. void sort() - sort the list by ascending order of info. 13. void dele(Node p) - delete node p if it exists in the list. 14. int[] toArray() - create and return array containing info of all nodes in the list. 15. Merge two ordered singly linked lists of integers into one ordered list. 16. void addBefore(Node p, int x) - add a node with value x before the node p. 17. Attach a singly linked list to the end of another singly linked list. 18. int max() - find and return the maximum value in the list. 19. int min() - find and return the minimum value in the list. 20. int sum() - return the sum of all values in the list. 21. int avg() - return the average of all values in the list.


We have an Answer from Expert

View Expert Answer

Expert Answer


class LinkedList { Node head; // head of list /* Linked list Node*/ class Node { int data; Node next; Node(int d) {data = d; next = null; } } /* Inserts a new Node at front of the list. */ public void addToHead(int x) { Node new_node = new Node(x); n
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe