Skip to content

Instantly share code, notes, and snippets.

View pulkitnehra's full-sized avatar
🎯
Focusing

Pulkit Nehra pulkitnehra

🎯
Focusing
View GitHub Profile
@pulkitnehra
pulkitnehra / heapifyt.java
Last active June 22, 2020 04:57
Heapify function in java
static void heapify(int arr[], int n, int i) {
// Find largest among root, left child and right child
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;
if (left < n && arr[left] > arr[largest])
largest = left;
if (right < n && arr[right] > arr[largest])
@pulkitnehra
pulkitnehra / HeapSort.java
Created June 22, 2020 05:00
Implementation of Heap Sort in Java
public class HeapSort {
public static void main(String[] args) {
int arr[] = {3,37,29,5,7,4,3,2,5,6,29,7,9,3,8,21,15,16,9,55,8,10,101,57,9,12};
System.out.println("Before heapsort the array is: ");
printlist(arr);
sort(arr);
System.out.println("\nAfter heap sort the array is: ");
printlist(arr);
}
@pulkitnehra
pulkitnehra / Sort.java
Last active June 22, 2020 06:32
Working of Heap sort
static void sort(int arr[])
{
// to sort the elements
int n = arr.length;
// build max heap
for(int i = n/2 - 1 ;i>=0; i--)
{
// i=n/2-1 as it will give us the left and right child nodes at the first level of the heap
heapify(arr,n,i);
}
@pulkitnehra
pulkitnehra / Appv1.java
Last active August 13, 2020 15:43
A simple GUI application for JDBC
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Appv1 extends Conn implements ActionListener{
// all elements must be static for results to display correctly
static JFrame f,j2;
static JTextField t1, t2, t3, t4, t5, t6, t7;
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Create a new user</title>
</head>
<body>