{
}
Online Python Compiler
Online R Compiler
Online SQL Editor
Online HTML/CSS Editor
Online Java Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online JavaScript Compiler
Online Typescript Compiler
Typescript Online Compiler
Online GoLang Compiler
Online Rust Compiler
Scala Online Compiler
Dart Online Compiler
Ruby Online Compiler
Online PHP Compiler
Online Swift Compiler
Generating Link
Generating Link
Share your code
Share code
Copy Link
Copied to clipboard
or share using
Black
83
%
Off
November
Ends in
Stop copy pasting code you don't actually understand
Build the coding confidence you need to become a developer companies will fight for
Stop copy pasting code you don't actually understand
Become a PRO
Become a PRO
Black
83
%
Off
November
Ends in
Stop copy pasting code you don't actually understand
Build the coding confidence you need to become a developer companies will fight for
Stop copy pasting code you don't actually understand
Become a PRO
Become a PRO
Online Java Compiler
Learn Python App
Learn Python
Main.java
Output
Main.java
Share
Run
Run
import java.util.Scanner; class Node{ int val; Node next; Node(int val){ this.val=val; } } class Sll{ Node head; Node tail; int size; void insertAtEnd(int val){ Node temp = new Node(val); if(head==null) head=tail=temp; else { tail.next=temp; tail=temp; } size++; } void display(){ Node temp=head; while(temp!=null) { System.out.print(temp.val+" "); temp=temp.next; } System.out.println(); } void size(){ System.out.println("size is= "+size); } int GetLeftMiddle(){ Node temp=head; int len=0; while(temp!=null){ temp=temp.next; len++; } temp=head; int mid=len/2; for(int i=1; i<=mid-1; i++){ temp=temp.next; } return temp.val; } } public class Implement { public static void main(String[] args) { Scanner sc =new Scanner(System.in); Sll list = new Sll(); list.insertAtEnd(5); list.insertAtEnd(6); list.insertAtEnd(7); list.insertAtEnd(8); list.display(); System.out.print("the value is= "+list.GetLeftMiddle()); } }
Output
Clear