1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Tanya [424]
3 years ago
10

Write a method max() which take a generic singly linked list as an argument and returns the maximum element reference in the lis

t.If the list is empty, please throw an empty collection exception.The method prototype is defined as follows.public static > T max(SingleLinkedList list) throws EmptyCollectionException.
Computers and Technology
1 answer:
max2010maxim [7]3 years ago
6 0

Answer:

See explaination

Explanation:

java code:

class DONALD

{

static class Node

{

int data;

Node next;

}

static Node head=null;

static int largestElement(Node head)

{

Int max=Integer.MIN_VALUE;

while(head!=null)

{

if(max<head.data)

max=head.data;

head=head.next;

}

return max;

}

static int smallestElement(Node head)

{

int min=Integer.MAX_VALUE;

while(head!=null)

{

if(min>head.data)

min=head.data;

head=head.next;

}

return min;

}

static void push(int data)

{

Node newNode=new Node();

newNode.data= data;

newNode.next=(head);

(head)=newNode;

}

static void printList(Node head)

{

while(head!=null)

{

System.out.println(head.data + " -> ");

head=head.next;

}

System.out.println("NULL");

}

public static void main(String[] args)

push(15);

push(14);

push(13);

push(22);

push(17);

System.out.println("Linked list is : ");

printList(head);

System.out.println("Maximum element in linked list: ");

System.out.println(largestelement(head));

System.out.print("Maximum element in Linked List: " );

System.out.print(smallestElement(head));

}

}

You might be interested in
What happens if i receive a text while my phone is off?
SIZIF [17.4K]
The text will post to your phone when it gets turned on
4 0
3 years ago
What does CTR stand for?
ipn [44]

click through rate is the answer


6 0
3 years ago
Read 2 more answers
Try making a character (string) variable and a logical variable . Try creating a variable with a "missing" value NA. You can cal
quester [9]

Answer:

The solution code is written in R script.

  1. #string variable
  2. character_str<- "Hello World"
  3. #logical variable
  4. logic <-  a > b
  5. #Missing value
  6. myVec <-c(1, 2, 3, NA)
  7. #Use class to check data type
  8. class(character_str)
  9. class(logic)
  10. class(myVec)

Explanation:

A string variable is a variable that hold a string (the letters enclosed within quotation marks) (Line 2)

A logical variable is a variable that hold a logical value (either True or False). The logical value is created by comparing two variables (Line 5).

In R, missing value is an unknown value which is represented by NA symbol (Line 8).  

We can use in-built method <em>class </em> to check for the variable type in R (Line 11-13). For example, the output of <em>class(character_str)</em> is "<em>character</em>"

8 0
3 years ago
Do software engineers save millions of dollars in usa
SCORPION-xisa [38]
Yes. They make a lot of money. So eventually after saving your Money, you will make a least 1 million dollars or more.
4 0
2 years ago
Why is color important for all objects drawn ?​
Sati [7]
Technically, drawing in colored pencil is simply layering semitransparent colors on paper to create vivid paintings. Every color has three qualities
7 0
3 years ago
Other questions:
  • Create a structure named planet This structure will contain distance from Earth as an integer Atmosphere, language, people and p
    8·1 answer
  • Black Ops 3 For Ps4 Players Here
    7·1 answer
  • 1 megabyte is equal to 1024 gigabyte. True/False​
    11·2 answers
  • A marketing associate wants to use the Validate button to ensure an email is CAN-SPAM compliant. What information does the assoc
    5·2 answers
  • The __________ assumption necessary for a linear programming model to be appropriate means that the contribution to the objectiv
    6·1 answer
  • If a*b = 2a - 56, calculate the value of<br>3 * 4​
    14·1 answer
  • If you said the bottom margin, you are talking about what?
    13·2 answers
  • What is the most vulnerable information that should be protected to prevent unauthorized access to your online files and records
    8·1 answer
  • I need help so bad it’s the entire test for EdHesive python coding Test 2
    5·1 answer
  • 1. Who was the first lady programmer?​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!