Programs
Programs
import java.io.*;
import java.util.*;
if(largest != i){
swap(arr, i, largest);
heapify(arr, n, largest);
}
}
private static void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
sort(arr);
for(int i : arr){
System.out.print(i+" ");
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT.
Your class should be named Solution. */
}
}
===================================================================================
===
Q.3
import java.io.*;
import java.util.*;
class ListNode{
int val;
ListNode next;
ListNode(int val){
this.val = val;
this.next = null;
}
}
public class Solution {
public static ListNode findMid(ListNode head){
ListNode slow = head;
ListNode fast = head;
curr = head;
while(curr !=null){}
System.out.print(curr.val +" ");
curr = curr.next;
}
System.out.println();
if(found){
System.out.println("Found");
}else{
System.out.println("Not Found");
}
}