Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main{
- static Node head;
- static class Node{
- int data;
- Node next;
- public Node(int data){
- this.data = data;
- this.next = null;
- }
- }
- public static void printFunction(){
- if(head == null){
- System.out.print("Linked List is Empty");
- }
- Node temp = head;
- while(temp != null){
- System.out.print(temp.data + " ");
- temp = temp.next;
- }
- System.out.println();
- }
- public static void main (String[] args) throws java.lang.Exception{
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- head = new Node(0);
- Node tmp = head;
- for(int i=0;i<n;i++){
- int data = sc.nextInt();
- Node node = new Node(data);
- tmp.next = node;
- tmp = tmp.next;
- }
- int position = sc.nextInt();
- head = head.next;
- if(head == null) return;
- Node curr = head;
- int count = 0;
- while(count < position){
- curr = curr.next;
- count++;
- }
- Node temp = curr.next;
- curr.next = curr.next.next;
- temp.next = null;
- printFunction();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement