In: Computer Science
import java.io.*;
import java.util.Scanner;
class Node {
int data;
Node next;
Node(int d){ // Constructor
data = d;
next = null;
}
}
class ACOLinkedList {// a Singly Linked List
Node head; // head of list
public void insert(int data){ // Method to insert a
new node
Node new_node = new Node(data); //
Create a new node with given data
new_node.next = null;
if (head == null) // If the Linked
List is empty, then make the new node as head
head =
new_node;
else {// Else traverse till the
last node and insert the new_node there
Node last =
head;
while (last.next
!= null)
last = last.next;
last.next =
new_node; // Insert the new_node at last node
}
}
}
class Main {
public static void main(String[] args)
{
ACOLinkedList list = new
ACOLinkedList();/* Start with the empty list. */
Scanner scan = new
Scanner(System.in);
int num;
for (int i=0; i<10; i++){//Read
list values
num =
scan.nextInt();
list.insert(num);
}
System.out.println(""+getMin(list));
}
public static int getMin(ACOLinkedList list) {
//TODO: Find the minimum element of
the linked list (list could have any number of elements)
//Example: if list={40, 20, 25, 15,
99}, the method should return: 15
}
}
import java.io.*;
import java.util.Scanner;
class Node {
int data;
Node next;
Node(int d) { // Constructor
data = d;
next = null;
}
}
class ACOLinkedList {// a Singly Linked List
Node head; // head of list
public void insert(int data) { // Method to insert a new node
Node new_node = new Node(data); // Create a new node with given data
new_node.next = null;
if (head == null) // If the Linked List is empty, then make the new node as head
head = new_node;
else {// Else traverse till the last node and insert the new_node there
Node last = head;
while (last.next != null)
last = last.next;
last.next = new_node; // Insert the new_node at last node
}
}
}
class Main {
public static void main(String[] args) {
ACOLinkedList list = new ACOLinkedList();/* Start with the empty list. */
Scanner scan = new Scanner(System.in);
int num;
for (int i = 0; i < 10; i++) {// Read list values
num = scan.nextInt();
list.insert(num);
}
System.out.println("" + getMin(list));
}
public static int getMin(ACOLinkedList list) {
Node trav = list.head;
if (trav == null)
return -1;
int min = trav.data;
while (trav != null) {
if (min > trav.data)
min = trav.data;
trav = trav.next;
}
return min;
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME