Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help LinkedList code: import java.util.*; public class LinkedList { public Node header; public LinkedList() { header = null; } public final Node Search(int key)

image text in transcribedplease help

LinkedList code:

import java.util.*;

public class LinkedList { public Node header;

public LinkedList() { header = null; }

public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; }

public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; }

public final Node Remove() { Node x = header; if (header != null) { header = header.link; } return x; }

public final Node searchPrevious(int key) { if (header == null) { return header; } else { Node current = header; while (!(current.link == null) && (current.link.item != key)) { current = current.link; } return current; } }

public final void Insert(int newItem, int preKey) { Node current; Node newNode = new Node(newItem); current = Search(preKey); if (current == null) { System.out.println("there is no such preKey!"); } else { newNode.link = current.link; current.link = newNode; } }

public final void Delete(int key) { if (header == null) // The list is empty! { System.out.println("The list is empty!"); } else { if (header.item == key) // header to be deleted. { header = header.link; } else { Node p = searchPrevious(key); if (p.link == null) { System.out.println("There is no such item!"); } else { p.link = p.link.link; } } } }

public final void ShowLinkedList() { if (header == null) System.out.println("The list is empty!"); else { Node current = header; System.out.printf("%1$s->", current.item); while (!(current.link == null)) { current = current.link; System.out.printf("%1$s->", current.item);

} System.out.printf("null"); System.out.println(); } } public final void PrintList() { if (header == null) { System.out.println("The list is empty!"); } else { Node current = header; System.out.println(current.item); while (!(current.link == null)) { current = current.link; System.out.println(current.item); } } } }

(30) Modify Linked List.java programs so that it handles employee objects. Make your program menu-driven. The class employee is the given below: le case licit Soring double salary w rout) SC d Systu r ID: "); a rs Scanner(Syst. ) System.out.println("Enter Salary: "); salary - Dur a ts.in.tel); public Output) Systes.ut.printf("m: S , ID: Grade 35 , id, lary); public Stringtoring reture String.format("omer 235, ID: 225s, Salary: 235s, nome, 1, Salary a) Search for an employee when the employee's ID is given b) Insert an employee to the linked list. c) Delete an employee from the linked list. d) Append an employee to the header of the linked list. e) Remove an employee from the header of the linked list. 1) Find the average salary of the employees in the linked list. g) Find the employee with highest salary (Note, you must return the employee, not just the highest salary)

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions